Aligning images

ABSTRACT

Some embodiments provide a method of aligning a pair of images. The method defines multiple different pairs of images at multiple different resolutions. The method hierarchically aligns the original pair of images by first aligning the pair of images at the lowest resolution and then aligning each pair of images at each higher resolution based on the alignments of the pair of images at the lower resolutions. For some of the resolutions, to perform the hierarchically alignment, the method identifies, for at least one image at each resolution, portions that are suitable for performing the alignment and portions that are not suitable for performing the alignment. The method compares each pair of images at a particular resolution by using the suitable portions while excluding the unsuitable portions from the comparison.

CLAIM OF BENEFIT TO PRIOR APPLICATIONS

This application claims benefit to U.S. Provisional Patent Application61/361,516, filed Jul. 5, 2010, U.S. Provisional Patent Application61/361,525, filed Jul. 6, 2010, and U.S. Provisional Patent Application61/378,933, filed Aug. 31, 2010. U.S. Provisional Patent Applications61/361,516, 61/361,525, and 61/378,933 are incorporated herein byreference.

CROSS REFERENCE TO RELATED APPLICATIONS

This Application is related to the following applications: U.S. patentapplication Ser. No. 12/876,095, filed Sep. 3, 2010; and U.S. patentapplication Ser. No. 12/876,100, filed Sep. 3, 2010.

BACKGROUND

In recent years, there has been a proliferation of digital cameras, asstandalone devices and as parts of more complex devices, such ascellular phones, smart phones, other mobile computing devices, etc. Withthis proliferation, manufacturers have rapidly increased the technicalfeatures of the digital cameras on these devices. For instance, manymobile devices today typically include five megapixel cameras, which areoften needed to produce high quality images.

Unfortunately, even though the technical specifications of such camerashave improved, these cameras often cannot capture and produce highquality images because the image processing capabilities of thesecameras have not matched their improving hardware capabilities. Forinstance, many cameras today still do a poor job of capturing andproducing images with high dynamic range (HDR).

A classic example of an HDR scene is a person standing indoors in frontof a window during daytime. Many cameras capturing such a scene producean image that has a bright background with a dark foreground that doesnot show all the features of the person. The problem of capturing suchan HDR scene by a mobile device's camera (e.g., by a phone's camera) isexacerbated by the small image sensors employed by such a camera.

BRIEF SUMMARY

Some embodiments of the invention provide a mobile device that capturesand produces images with high dynamic ranges. To capture and produce ahigh dynamic range image, the mobile device of some embodiments includesnovel image capture and processing modules. In some embodiments, themobile device produces a high dynamic range (HDR) image by (1) havingits image capture module rapidly capture a succession of images atdifferent image exposure durations, and (2) having its image processingmodule composite these images to produce the HDR image.

To rapidly capture a succession of images, the image capture module ofsome embodiments takes two actions. First, after the mobile deviceenters its HDR mode or after it enters an image-capture mode (alsoreferred to, below, as a camera mode), it starts capturing images at aparticular frame rate. In some embodiments, the frame rate is about 15frames per second (fps). In other embodiments, the initial frame rate isdifferent under different lighting conditions (e.g., 15 fps for normallighting conditions, 10 fps for darker conditions, etc.). This framerate allows the camera to capture images at the normal exposure settingfor the current lighting condition (i.e., allows the camera to captureeach image with an exposure duration that the image capture modulecomputes as the normal exposure duration for the current lightingcondition). The image capture module stores each image that it capturesat the particular frame rate in a frame buffer of the device. In someembodiments, the capture module writes to this frame buffer in acircular manner that allows the module to delete earlier stored framesbefore later stored frames when the buffer reaches its maximum storagecapacity.

Second, when the mobile device enters a high dynamic range (HDR) mode,the image capture module computes the exposure durations for capturingan underexposed image and an overexposed image for the lightingcondition under which the camera is capturing the images (referred to,below, as the current lighting condition). Different embodiments of theinvention employ different techniques for computing the durations of theoverexposed and underexposed images. For instance, some embodimentscompute the duration of the overexposed and underexposed images based ona histogram of the normally exposed images that the device is capturingat the particular frame rate.

After the device enters its HDR mode, the device can be directed to takean HDR image (e.g., by the user of the device, by a timer on the device,by a remote user or timer, etc.) When the device is directed to take theHDR image, the image capture module of some embodiments then capturestwo images in quick succession. One image is an overexposed image thatit captures based on the overexposed duration that it previouslycomputed for the current lighting condition, while the other image isthe underexposed image that it captures based on the underexposedduration that it previously computed for the current lighting condition.In different embodiments, the image capture module captures theoverexposed and underexposed images in different orders (e.g., someembodiments capture the overexposed image first, while other embodimentscapture the underexposed image first).

In addition to capturing the overexposed and underexposed images, theimage capture module also retrieves an image that it captured earlier atthe normal exposure duration and stored in its frame buffer. This moduleprovides each of the three images to the image processing module. Insome embodiments, the image capture module provides the three images inthe color space in which the camera captured the images. For example,the image capture module of some embodiments captures and provides theseimages in the Y′CbCr (luma, blue-chroma, and red-chroma) color space.Some embodiments reverse gamma correct the camera's Y′CbCr (luma) imagesto YCbCr (luminance, blue-chroma, red-chroma) images before performingvarious image editing operations and then gamma correct the resultingYCbCr (luminance) image to a Y′CbCr (luma) image.

The image processing module then performs two operations. The firstoperation is an alignment of all three images with each other, as thecamera might have moved during the time that it captured the threeimages. Different embodiments perform this alignment differently. Forinstance, to align two images, some embodiments perform a hierarchicalsearch that tries to identify matching features in the two images. Toidentify matching features, some embodiments examine only the lumacomponent (e.g., Y′-channel component for a Y′CbCr color space) of thetwo images. The luma component of an image is sometimes referred toherein as a “luma image” or as an “image”. The two luma images aredecimated by a certain factor (e.g., two) in each direction severaltimes (e.g., six times) until several pairs of luma images areidentified. Each pair of luma images is used for performing the searchat a different level in the search hierarchy. At each level, a bitmap isgenerated for each luma image (e.g., by using the median luma value forthat level to generate pixel values to 1 or 0 based on whether they aregreater or less than the median value).

At each level, at least one bitmap is divided into several tiles witheach tile encompassing several pixels. The tiles are used to identifycorresponding matching tiles in the other bitmap, and thereby identifyan offset between the two bitmaps. In some embodiments, some of thetiles are discarded when the tiles contain only white pixels, only blackpixels, less than a threshold of white pixels, or less than a thresholdof black pixels. These tiles are tiles that do not have a sufficientnumber of features (e.g., edges) that can be used to match up with othertiles. These tiles are discarded in order to speed up the process forcomparing the tiles and thereby identifying the offset between the twopairs of bitmaps.

Based on the remaining tiles, the two bitmaps are compared at variousdifferent offsets in order to identify the offset that best aligns thetwo bitmaps at the current resolution level of the hierarchy. If thecurrent resolution level of the hierarchy is not the highest resolutionlevel of the hierarchy, the image processing module of some embodimentsthen uses the computed offset for the current resolution level of thehierarchy as the starting point for searching in the next level of thehierarchy. In this next level, the module again generates two bitmapsfor the two different luma images for that level of the hierarchy, andthen searches for an offset starting at the specified starting point forthe search.

In the hierarchical comparison of the luma component of two images, theoffset that is identified at the highest level of the hierarchy is theoffset between the two images. Once the image processing module hasdetermined this offset between one image (e.g., the regularly exposedimage) and each of the other images (e.g., the overexposed image and theunderexposed image), it uses these offsets to align the three images.For instance, in some embodiments, it uses these two offsets to crop thethree images so that they all only include overlapping portions of thesame scene. Alternatively, instead of cropping all three images, someembodiments only crop the overexposed and underexposed images and forthe portions of these images that get cropped, use the data from thenormally exposed image to generate the composite HDR image. Also,instead of cropping the images, other embodiments might use otheroperations (e.g., they might identify the union of the images) toaddress non-overlapping regions in the images. Some embodiments do notcrop and instead repeat edge pixels. Repeating edge pixels leads toacceptable results since the offset between images is typically small.

Also, chroma is typically in a Y′CbCr 4:2:2 or 4:2:0 format. This meansthat the sampling of chroma is different than luma. In 4:2:2, chroma ishalf the horizontal size of luma, while in 4:2:0, chroma is half thehorizontal size and half the vertical size of luma. Accordingly, whenaligning the images, some embodiments adjust the vector for chroma basedon this format.

After aligning the images, the image processing module performs itssecond operation, which is the compositing of the three aligned imagesto produce a composite HDR image. In different embodiments, the imageprocessing module uses different techniques to composite the threeimages. For instance, some embodiments composite the three images byperforming different sets of operations for the luma channel of theseimages than for the chroma channels of these images. Also, in generatingthe HDR composite image, some embodiments might produce luma and chromavalues that exceed a desired range of values. Accordingly, whilegenerating the HDR image, some embodiments concurrently perform scalingoperations to ensure that the luma and chroma values of the HDR imageare generated within their desired ranges.

One of ordinary skill in the art will realize that the image capture andprocessing operations can be implemented differently than thosedescribed above. For instance, instead of returning only one normallyexposed image from the frame buffer, the image capture module of someembodiments returns several normally exposed images to the imageprocessing module. From this group, the image processing module thenselects the normally exposed image that is the sharpest and that bestmatches the captured overexposed and underexposed images. Alternatively,in some embodiments, the image capture module only returns one normallyexposed image, but tries to ensure that this returned image is notblurred (i.e., is sharp). In different embodiments, the image capturemodule tries to ensure that the image is sharp in different ways. Forinstance, in some embodiments where the device has an accelerometerand/or gyroscope, the image capture module uses data recorded from theaccelerometer and/or gyroscope to ascertain the likelihood of theblurriness of the normally exposed images in order to select a normallyexposed image that is sharp. Alternatively, in some embodiments, ratherthan using normally exposed images from the frame buffer, after an HDRcommand is received, the mobile device takes one or more images at anormal exposure as well as the overexposed and underexposed images. Insome such embodiments, the image processing module selects one of thenormally exposed images (e.g., the sharpest, the last, etc.) to use forgenerating a composite HDR image.

The preceding Summary is intended to serve as a brief introduction tosome embodiments of the invention. It is not meant to be an introductionor overview of all inventive subject matter disclosed in this document.The Detailed Description that follows and the Drawings that are referredto in the Detailed Description will further describe the embodimentsdescribed in the Summary as well as other embodiments. Accordingly, tounderstand all the embodiments described by this document, a full reviewof the Summary, Detailed Description and the Drawings is needed.Moreover, the claimed subject matters are not to be limited by theillustrative details in the Summary, Detailed Description and theDrawings, but rather are to be defined by the appended claims, becausethe claimed subject matters can be embodied in other specific formswithout departing from the spirit of the subject matters.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates a mobile device that captures and produces imageswith high dynamic ranges.

FIG. 2A illustrates the invocation of a high dynamic range (HDR) mode,and the taking of an HDR picture in this mode, in a mobile device ofsome embodiments.

FIG. 2B illustrates the display of a preview image during the invocationof a high dynamic range (HDR) mode, and the taking of an HDR picture inthis mode, in a mobile device of some embodiments.

FIG. 3 conceptually illustrates the software architecture of the mobiledevice of some embodiments.

FIG. 4 illustrates the operation of an image processing module during anHDR image capture session.

FIG. 5A illustrates the image capture module of some embodiments of theinvention.

FIG. 5B illustrates the image capture module of some other embodimentsof the invention.

FIG. 6 illustrates a process that conceptually represents a series ofoperations of the image capture module during an HDR image capturesession.

FIG. 7 illustrates a process of some embodiments for generating a seriesof bitmaps for aligning images.

FIG. 8 illustrates examples of bitmaps made from decimated images ofsome embodiments.

FIG. 9 illustrates a process of some embodiments for determining anoffset vector that aligns two images.

FIG. 10 illustrates a process for determining an offset vector foraligning two bitmaps.

FIG. 11 illustrates an example of the determination of a final offsetvector.

FIG. 12 illustrates a process for compositing the luma channel images ofthree different exposures of the same scene and adjusting various lumavalues of the resulting composite image.

FIG. 13A illustrates an example of performing a compositing process on aparticular scene.

FIG. 13B illustrates an example of performing the compositing processwhile generating masks from separate images.

FIG. 14 illustrates a process of some embodiments for compositing chromachannel images.

FIG. 15 illustrates an example of compositing chroma channel images insome embodiments.

FIG. 16 is an example of a mobile computing device 1600 of someembodiments.

FIG. 17 illustrates a touch I/O device.

DETAILED DESCRIPTION

In the following detailed description of the invention, numerousdetails, examples, and embodiments of the invention are set forth anddescribed. However, it will be clear and apparent to one skilled in theart that the invention is not limited to the embodiments set forth andthat the invention may be practiced without some of the specific detailsand examples discussed.

Some embodiments of the invention provide a mobile device that capturesand produces images with high dynamic ranges. FIG. 1 illustrates onesuch mobile device 100. This mobile device can be a camera, a mobilephone, a smart phone, a personal digital assistant (PDA), a tabletpersonal computer (such as an iPad®), a laptop, or any other type ofmobile computing device. FIG. 1 illustrates the mobile device 100capturing a digital picture of a scene with a high dynamic range. Inthis scene, a person is standing in front of a window on a sunny daywhile a car is driving in the background.

FIG. 1 also illustrates that the mobile device 100 produces a highdynamic range image 180 by capturing, aligning and compositing threeimages 135, 140, and 145 that are captured at three different exposuresettings. As shown in this figure, the mobile device 100 includes animage capture module 105 and an image processing module 110, whichperform operations that allow the mobile device to capture and produce ahigh dynamic range image. In some embodiments, the mobile deviceproduces a high dynamic range (HDR) image by (1) having its imagecapture module rapidly capture a succession of images at different imageexposure durations, and (2) having its image processing module compositethese images to produce the HDR image. While the description hereinincludes three images, one of ordinary skill in the art will realizethat some embodiments use more than three images (e.g., some embodimentsuse five images very overexposed, overexposed, normal, underexposed andvery underexposed). Some embodiments use variable numbers of imagesunder various conditions.

To rapidly capture a succession of images, the image capture module ofsome embodiments takes two actions when the camera enters a high dynamicrange (HDR) mode. First, it starts capturing images at a particularframe rate. In some embodiments, the frame rate is about 15 frames persecond (fps). In other embodiments, the initial frame rate is differentunder different lighting conditions (e.g., 15 fps for normal lightingconditions, 10 fps for darker conditions, etc.). This frame rate allowsthe camera to capture images at the normal exposure setting for thecurrent lighting condition (i.e., allows the camera to capture eachimage with an exposure duration that the image capture module computesas the normal exposure duration for the current lighting conditions).The image capture module stores each image that it captures at theparticular frame rate in a frame buffer (not shown) of the device. Insome embodiments, the capture module writes to this frame buffer in acircular manner that allows the module to delete earlier stored framesbefore later stored frames when the buffer reaches its maximum storagecapacity.

Second, for the lighting condition under which the camera is capturingthe images (referred to below as the current lighting condition), theimage capture module computes the exposure durations for capturing anunderexposed image and an overexposed image. For instance, someembodiments compute the duration of the overexposed and underexposedimages based on the histogram of the normally exposed images that thedevice is capturing at the particular frame rate. For example, if thenormally exposed image has a large number of saturated pixels, then theduration of the overexposed image is set to a smaller multiple of thenormal exposure duration than it would be if the normally exposed imagehad fewer saturated pixels.

After the device enters its HDR mode, the device can be directed to takean HDR image (e.g., by the user of the device, by a timer on the device,by a remote user or timer, etc.) When the device is directed to take theHDR image, the image capture module of some embodiments then capturestwo images in quick succession. One image is an overexposed image thatit captures based on the overexposed duration that it previouslycomputed for the current lighting condition, while the other image isthe underexposed image that it captures based on the underexposedduration that it previously computed for the current lighting condition.In different embodiments, the image capture module captures theoverexposed and underexposed images in different orders (e.g., someembodiments capture the overexposed image first, while other embodimentscapture the underexposed image first).

In addition to capturing the overexposed and underexposed images, theimage capture module also retrieves an image that it captured earlier atthe normal exposure duration and stored in its frame buffer (e.g., themost recent image taken before the HDR capture command). The imagecapture module 105 provides each of the three images to the imageprocessing module 110. FIG. 1 illustrates these three images as anoverexposed image 135, a normally exposed image 140, and an underexposedimage 145 at the output of the image capture module 105. In someembodiments, the image capture module provides the three images in thecolor space in which the camera captured the images. For example, theimage capture module of some embodiments captures and provides theseimages in the Y′CbCr color space.

The above description includes taking multiple images at a normalexposure duration before an HDR capture command is received and takingthe overexposed and underexposed images after the HDR capture command isreceived. However, in some embodiments, multiple underexposed images aretaken before the HDR capture command is received and the normallyexposed and overexposed images are taken after the HDR capture commandis received. Additionally, in some embodiments, multiple overexposedimages are taken before the HDR capture command is received and thenormally exposed and underexposed images are taken after the HDR capturecommand is received.

As shown in FIG. 1, the image processing module 110 in some embodimentsincludes (1) an alignment module 115 that aligns the three images thatit receives and (2) a compositing module 120 that composites the threeimages that it receives to produce the HDR image 180. The alignmentmodule aligns all three images with each other, as the camera might havemoved during the time that it captured the three images.

As further shown in FIG. 1, the alignment module 115 in some embodimentsincludes (1) a search module 125 that compares the images to align themand (2) a cropping module 130 that crops one or more of the alignedimages to only include the areas that overlap between the images. Toalign two images, the search module 125 performs a search that tries toidentify matching features in the two images. To do this, someembodiments examine only the luma component (e.g., Y′-channel componentfor a Y′CbCr color space) of the two images.

In some embodiments, the search module 125 performs a hierarchicalsearch that initially decimates two luma images by a certain factor(e.g., two) in each direction several times (e.g., six times) untilseveral pairs of luma images are identified. Each pair of luma images isused for performing the search at a different level in the searchhierarchy. At each level, a bitmap is generated for each luma image(e.g., by using the median luma value for that level to generate pixelvalues to 1 or 0 based on whether they are greater or less than themedian value).

At each level, the search module divides at least one bitmap intoseveral tiles with each tile encompassing several pixels. The moduleuses the tiles to identify corresponding matching tiles in the otherbitmap, and thereby identify an offset between the two bitmaps. In someembodiments, the search module discards some of the tiles when the tilescontain only white pixels, only black pixels, less than a threshold ofwhite pixels, or less than a threshold of black pixels. These tiles aretiles that do not have sufficient number of features (e.g., edges) thatcan be used to match up with other tiles. These tiles are discarded inorder to speed up the process for comparing the tiles and therebyidentifying the offset between the two pairs of bitmaps.

Based on the remaining tiles, the search module compares the two bitmapsat various different offsets in order to identify the offset that bestaligns the two bitmaps at the current resolution level of the hierarchy.If the current resolution level of the hierarchy is not the highestresolution level of the hierarchy, the search module then uses thecomputed offset for the current resolution level of the hierarchy as thestarting point for searching in the next level of the hierarchy. In thisnext level, the module again generates two bitmaps for the two differentluma images for that level of the hierarchy, and then searches for anoffset starting at the specified starting point for the search.

In the hierarchical comparison of the luma component of two images, theoffset that is identified at the highest level of the hierarchy is theoffset between the two images. Once the search module 125 completes itshierarchical searching of the two pairs of images, it identifies twooffsets that define the translation of two of the images so that allthree images are aligned. In the example illustrated in FIG. 1, thesearch module in some embodiments compares the luma component of theunderexposed/overexposed image with the luma component of the regularlyexposed image. This comparison identifies two offsets, one defining thetranslation between the underexposed luma image and normally exposedimage, and the other defining the translation between the overexposedluma image and the normally exposed image. These two offsets, in turn,identify how the three images can be aligned as indicated by the dashedlines in FIG. 1 that identify the matching regions in the three lumaimages 150, 155 and 160.

Once the search module 125 has determined this offset between one image(e.g., the regularly exposed image) and each of the other images (e.g.,the overexposed image and the underexposed image), the cropping module130 uses these offsets to trim the three images. Specifically, in someembodiments, it uses these two offsets to crop the three images so thatthey all only include overlapping portions of the same scene. FIG. 1illustrates the results of this cropping by showing the cropped, alignedimages 165, 170 and 175. Instead of cropping all three images, someembodiments only crop the overexposed and underexposed images and forthe portions of these images that get cropped, use the data from thenormally exposed image to generate the composite HDR image.Alternatively, instead of cropping the images, other embodiments mightuse other operations (e.g., they might identify the union of the images)to address non-overlapping regions in the images. Some embodiments donot crop and instead repeat edge pixels. Repeating edge pixels leads toacceptable results since the offset between images is typically small.

Also, chroma is typically in a Y′CbCr 4:2:2 or 4:2:0 format. This meansthat the sampling of chroma is different than luma. In 4:2:2, chroma ishalf the horizontal size of luma, while in 4:2:0, chroma is half thehorizontal size and half the vertical size of luma. Accordingly, whenaligning the images, some embodiments adjust the vector for chroma basedon this format.

As shown in this figure, the compositing module 120 receives thecropped, aligned images, which it then composites to produce thecomposite HDR image 180. In different embodiments, the compositingmodule uses different techniques to composite the three images. Forinstance, some embodiments composite the three images by performingdifferent sets of operations for the luma channel of these images thanfor the chroma channels of these images. Also, in generating the HDRcomposite image, some embodiments might produce luma and chroma valuesthat exceed a desired range of values. Accordingly, while generating theHDR image, the compositing module 120 of some embodiments concurrentlyperforms scaling operations to ensure that the luma and chroma values ofthe HDR image are generated within their desired ranges.

One of ordinary skill in the art will realize that the image capture andprocessing operations can be implemented differently than thosedescribed above. For instance, instead of returning only one normallyexposed image from the frame buffer (e.g., the most recent image), theimage capture module of some embodiments returns several normallyexposed images to the image processing module. From this group, theimage processing module then selects the normally exposed image that isthe sharpest and/or that best matches the captured overexposed andunderexposed images. Alternatively, in some embodiments, the imagecapture module only returns one normally exposed image, but tries toensure that this returned image is not blurred (i.e., is sharp). Indifferent embodiments, the image capture module tries to ensure that theimage is sharp in different ways. For instance, in some embodimentswhere the device has an accelerometer and/or gyroscope, the imagecapture module uses data recorded from the accelerometer and/orgyroscope to ascertain the likelihood of the blurriness (e.g., toquantify one or more motion related attributes) of the normally exposedimages in order to select a normally exposed image that is sharp. Insome embodiments, the image capture module selects the most recent imagethat is not likely to be blurred (e.g., has motion related attributesthat are below a certain motion threshold). Instead of, or in additionto using motion detecting sensors, some embodiments determine which ofmultiple images is sharpest by using digital signal processingtechniques to determine the frequency content of each image. In suchembodiments, the image with the highest frequency content is identifiedas the sharpest image.

Alternatively, in some embodiments, rather than using normally exposedimages from the frame buffer, after an HDR capture command is received,the mobile device takes one or more images at a normal exposure as wellas the overexposed and underexposed images. In some such embodiments,the image processing module selects one of the normally exposed images(e.g., the sharpest, the last, etc.) to use for generating a compositeHDR image.

Several more detailed embodiments of the invention are described below.Section I describes how the user interface of some embodiments allows auser to invoke an HDR mode and to capture an HDR image. Section II thendescribes the software architecture that the media device uses in someembodiments to capture and process HDR images. Next, Section III furtherdescribes the image capture module of the mobile device of someembodiments. Section IV then describes the image alignment process ofthe mobile device's image processing module in some embodiments. SectionV next describes the image compositing process of the mobile device'simage processing module in some embodiments. Lastly, Section VIdescribes a system architecture of the mobile device of someembodiments.

I. Invocation of HDR Mode and HDR Capture

In some embodiments, HDR mode is indicated by selection in a userinterface (UI) of a mobile device. FIG. 2A illustrates the invocation ofthe HDR mode and the taking of an HDR picture during this mode, in amobile device 200 of some embodiments. This figure illustrates theseoperations in six stages, 245, 250, 255, 257, 260, and 265 of the userinterface of the device 200.

As shown in FIG. 2A, the mobile device 200 includes a display area 220,an image capture UI item 215, and a flash UI item 210. The display area220 in some embodiments displays an image of a scene captured by asensor of the mobile device when the mobile device has been placed in amode to operate as a camera. The image capture UI item 215 is a userselectable item that once selected by a user, directs the mobile deviceto capture one or more images.

In some embodiments, the mobile device includes a flash for the camera.Accordingly, in these embodiments, the flash UI item 210 allows the userto turn the flash on or off. As further described below, the flash UIitem 210 also allows a user to place the mobile device's camera in anHDR mode.

The operation of the mobile device 200 in capturing an HDR image willnow be described. The first stage 245 shows the user interface of themobile device after the device has been placed in an image capture mode.In some embodiments, a user can place the device in this mode byselecting a camera icon displayed in the display area 220. In someembodiments, when the device enters the camera mode, the device startscapturing images, storing these images temporarily in its frame buffer,and transiently displaying these images in the display area 220.However, in order to highlight the flash item 210 and the sequence of UIitems displayed and operations performed, the first through fourthstages 245-257 in FIG. 2A do not show any of the images that aretransiently displayed in the display area 220.

The second stage 250 shows the user selecting the flash UI item 210. Asshown in FIG. 2A, the user can make this selection by touching (e.g.,with a finger 225) the device's touch-screen display area at thelocation of the flash item 210. The user can also select this itemthrough other UI selection techniques in some embodiments.

The third stage 255 shows that the selection of the flash item 210results in the display of a flash menu 230. This menu has a selectableUI item 280 for turning on the flash, a selectable UI item 285 forturning off the flash, a selectable UI item 290 for setting the flash toan auto flash mode, and a selectable UI item 235 for turning on the HDRimage-capture mode. While the selectable HDR-mode item 235 is shown forsome embodiments to be part of the flash menu 230 in FIG. 2A, one ofordinary skill in the art will realize that this item 235 has adifferent placement in the UI of the device in some embodiments.

The fourth stage 257 illustrates a user's selection of the HDRmode-selection item 235. This selection is made by touching (e.g., witha finger 240) the location of this item on the mobile device's displaytouch screen. In some embodiments, the user can also select this modethrough other UI selection techniques.

The fifth stage 260 illustrates a user selecting the image capture item215 by touching (e.g., with a finger 270) the location of this item onthe mobile device's display touch screen. As with other selectable itemsin the display area, the user can select the image-capture item in someembodiments through other UI selection techniques. The selection of theitem 215 causes the device to capture an HDR image of the HDR scene (ofa person standing in front of a window on a sunny day) that the user isviewing in the display area 220. Again, even before entering the HDRmode and receiving the selection of the image-capture item, the displayarea transiently displays the images, such as preview image 262, thatthe camera temporarily and repeatedly captures when it enters the cameramode. However, as mentioned above, these transiently displayed imagesare not shown in stages 245-257 of FIG. 2A in order not to obscure thedisplay of the UI items and the selection of various UI items.

The sixth stage 265 illustrates the HDR image 267 that the cameracaptures and stores upon the selection of the image-capture item 215.This image in some embodiments is the image-processed digital picturethat the device produces after having its image capture module captureseveral images at different exposures in sequence and having its imagecompositing modules composite these images. In some embodiments, the HDRimage 267 includes details that are not visible in the preview image262. For example, HDR image 267 includes birds 275.

As mentioned above, preview image 262 is not shown in the display inFIG. 2A in order not to obscure the display of the UI items and theirselection. Accordingly FIG. 2B illustrates the display of a previewimage 262 during the stages of the HDR capture operation described inrelation to FIG. 2A.

II. Software Architecture

FIG. 3 conceptually illustrates the software architecture 300 of themobile device of some embodiments. In some embodiments, this device cancapture images of HDR scenes, can processes these images to produce HDRimages, and can encode these images (e.g., as JPEG images). To do theseoperations, this device includes a capture module (CM) driver 305, amedia exchange module 310, an encoder driver 320, and an imageprocessing module 325, as shown in FIG. 3.

In some embodiments, the media exchange module 310 allows programs onthe device that are consumers and producers of media content to exchangemedia content and instructions regarding the processing of the mediacontent. Accordingly, in some embodiments, the media exchange module 310routes instructions and media content between the image processingmodule 325 and the CM driver 305, and between the image processingmodule 325 and the encoder driver 320. To facilitate the routing of suchinstructions and media content, the media exchange module 310 of someembodiments provides a set of application programming interfaces (APIs)for the consumers and producers of media content to use. In some suchembodiments, the media exchange module 310 is a set of one or moreframeworks that is part of an operating system running on the mobiledevice. One example of such a media exchange module 310 is the CoreMedia framework provided by Apple Inc.

The image processing module 325 performs image processing on the imagescaptured by the camera of the device. Examples of such operationsinclude exposure adjustment operations, focus adjustment operations,perspective correction, image resizing, etc. In addition to theseoperations, the image processing module 325 performs HDR imageprocessing operations. Specifically, in some embodiments, the module 325includes the HDR image processing module 110 of FIG. 1. With this module110, the module 325 performs the alignment and compositing operationsthat were described above by reference to FIG. 1.

Through the media exchange module 310, the image processing module 325interfaces with the CM driver 305 and the encoder driver 320, asmentioned above. The CM driver 305 serves as a communication interfacebetween an image capture module (ICM) 330 and the media exchange module310. The ICM 330 is the component of the mobile device that isresponsible for capturing a sequence of images at different resolutionsthat are needed to produce an HDR image.

From the image processing module 325 through the media exchange module310, the CM driver 305 receives instructions that the device has enteredan HDR mode and that an HDR image capture request has been made. The CMdriver 305 relays such requests to the ICM 330, and in response receivesthe necessary set of images at different resolutions for producing theHDR image. The CM driver 305 then sends these images to the imageprocessing module 325 through the media exchange module 310.

The encoder driver 320 serves as a communication interface between themedia exchange module 310 and an encoder hardware 335 (e.g., an encoderchip, an encoding component on a system on chip, etc.). In someembodiments, the encoder driver 320 receives images (e.g., generated HDRimages) and requests to encode the images from the image processingmodule 325 through the media exchange module 310. The encoder driver 320sends the images to be encoded to the encoder 335, which then performspicture encoding (e.g., JPEG encoding) on the images. When the encoderdriver 320 receives encoded images from the encoder 335, the encoderdriver 320 sends the encoded images back to the image processing module325 through the media exchange module 310.

In some embodiments, the image processing module 325 can performdifferent operations on the encoded images that it receives from theencoder. Examples of such operations include storing the encoded imagesin a storage of the device, transmitting the encoded images through anetwork interface of the device to another device, etc.

In some embodiments, some or all of the modules 305, 310, 320, and 325are part of the operating system of the device. Other embodimentsimplement the media exchange module 310, the CM driver 305, and theencoder driver 320 as part of the operating system of the device, whilehaving the image processing module 325 as an application that runs onthe operating system. Still other implementations of the module 300 arepossible.

The operation of the image processing module 325 during an HDR imagecapture session will now be described by reference to FIG. 4. Thisfigure illustrates conceptually a process 400 that represents one seriesof operations that the image processing module 325 performs in someembodiments to produce an encoded HDR image. The image processing module325 performs this process 400 each time the device enters the HDR mode(e.g., upon selection of the HDR selection item 235 in the exampleillustrated in FIG. 2A). Accordingly, as shown in FIG. 4, the imageprocessing module 325 initially enters (at 405) the HDR mode.

Next, the module 325 instructs (at 410) the image capture module 330 toenter its HDR image capture mode through the media exchange module 310and the CM driver 305. Upon receiving this instruction, the imagecapture module 330 computes the exposure durations for producingoverexposed and underexposed images at the current lighting conditions,as mentioned above and further described below. Also, at this stage, theimage capture module 330 is capturing normally exposed images andtemporarily storing them in a frame buffer. To capture such images, theimage capture module 330 computes exposure duration repeatedly while thedevice is in its camera mode operation.

After instructing the image capture module 330 to enter its HDR mode,the image processing module 325 instructs (at 415) the image capturemodule 330 that it has received a command to capture and produce an HDRimage (e.g., upon selection of the picture capture item 215 in theexample illustrated in FIG. 2A). This instruction is relayed to theimage capture module 330 through the media exchange module 310 and theCM driver 305.

In response to this instruction, the image capture module 330 capturesin quick succession an overexposed image that it captures based on theoverexposed duration that it previously computed for the currentlighting condition, and an underexposed image that it captures based onthe underexposed duration that it previously computed for the currentlighting condition. In addition to these images, the image capturemodule also retrieves an image that it captured earlier at the normalexposure duration and stored in its frame buffer.

Through the CM driver 305 and the media exchange module 310, the imageprocessing module 325 receives (at 415) each of the three images fromthe image capture module 330. In some embodiments, the image processingmodule 325 receives the three images in the color space in which thecamera captured the images. For example, the image capture module 330 ofsome embodiments captures and provides these images in the Y′CbCr colorspace.

The image processing module then aligns (at 420) all three images witheach other, as the camera might have moved during the time that itcaptured the three images. As mentioned above and further describedbelow, the image processing module uses a hierarchical search techniqueto pairwise align the overexposed and the underexposed images with theregularly exposed image.

After aligning the images, the image processing module composites (at425) the image data in the three images to produce a composite HDRimage. In different embodiments, the image processing module usesdifferent techniques to composite the three images. For instance, someembodiments composite the three images by performing different sets ofoperations for the luma channel of these images than for the chromachannels of these images. Also, in generating the HDR composite image,some embodiments might produce luma and chroma values that exceed adesired range of values. Accordingly, while generating the HDR image,some embodiments concurrently perform scaling operations to ensure thatthe luma and chroma values of the HDR image are generated within theirdesired ranges.

After producing the HDR image, the image processing module displays (at425) the generated HDR image. Next, this module directs (430) theencoder 335 (through the media exchange module 310 and the encoderdriver 320) to encode the HDR image. The encoder in some embodimentsencodes this image (e.g., encodes it into a JPEG format) and returns theencoded HDR image. The image processing module in some embodiments thenstores (at 430) the encoded HDR image on a storage of the device. Theimage processing module of some embodiments can also perform otheroperations with the encoded HDR image. For instance, in some cases, theimage processing module transmits the encoded generated image to anotherdevice through a network connection established by the network interfaceof the device.

One of ordinary skill in the art will realize that the image processingoperations can be implemented differently than those described above.For instance, instead of only processing one normally exposed image, theimage processing module of some embodiments examines several normallyexposed images that the image capturing module returns. From this group,the image processing module selects the normally exposed image that isthe sharpest and that best matches the captured overexposed andunderexposed images. Alternatively, in some embodiments, rather thanusing normally exposed images from the frame buffer, after an HDRcapture command is received, the mobile device takes one or more imagesat a normal exposure as well as the overexposed and underexposed images.In some such embodiments, the image processing module selects one of thenormally exposed images (e.g., the sharpest, the last, etc.) to use forgenerating a composite HDR image. In some embodiments, the normallyexposed images are taken after the HDR capture command rather than fromthe frame buffer.

One of ordinary skill in the art will understand that each method,taking the normal image from a frame buffer and taking the normal imageafter the HDR command is received, has some advantages over the other.The act of touching the HDR capture command icon moves the mobile deviceaway from where it was when the images in the frame buffer were taken.In an image from the frame buffer is used, the movement of the mobiledevice caused by touching the HDR capture command icon will occurbetween the taking of the normally exposed image and the overexposed andunderexposed images. If instead, a fresh normally exposed image is takenafter the HDR capture command icon is touched, the movement caused bythe touch will occur before the normal image is taken, rather thanbetween the capture of the images. Accordingly, taking a fresh normallyexposed image can reduce the amount of movement of the device during thecapturing of the three exposures. Reducing the movement during thecapturing of the images increases the overlapping area to be composited.

As mentioned above, some embodiments display recent images from theframe buffer as preview images, and use one of the preview images as thenormally exposed image. A possible advantage of using a normal imagefrom the frame buffer is that the image would look more like the previewimage displayed before the HDR capture command is received. Anotherpossible advantage to retrieving the normal image from the frame bufferis that the time between the HDR command being activated and thecomposite HDR image being displayed may be shorter (e.g., by theexposure time of the normally exposed image).

Because some embodiments use a newly captured normal exposure, ratherthan an image from the frame buffer, some of those embodiments do nottake normally exposed preview images and store them in the frame bufferwhile the mobile device is in HDR mode. However, even among embodimentsthat use normally exposed images captured after the HDR command isreceived, some embodiments still take normally exposed preview images inorder to collect data about the lighting conditions, determine whatnormal exposure time to use, what exposure values to use, etc.

III. Image Capture Module

FIG. 5A illustrates the image capture module 330 of some embodiments ofthe invention. At the direction of the image processing module 325, theimage capture module 330 directs the device's camera to capture images.For instance, as mentioned above, the image capture module 330 in someembodiments directs the camera to start capturing normally exposedimages at a particular frame rate when the device enters its camera modeof operation. Also, when the device enters its HDR mode, the module 330enters its HDR mode (at the direction of the image processing module325) by computing exposure durations for taking overexposed andunderexposed images. Subsequently, when it receives a capture imagecommand while it is in its HDR mode, the image capture module 330 insome embodiments (1) takes two successive images, one with theoverexposed duration and one with the underexposed duration, and (2)returns these two images along with one or more normally exposed imagesfrom its frame buffer.

As shown in FIG. 5A, the image capture module 330 includes a sensormodule 515, a frame buffer 520, an image processing pipeline 525, astatistics engine 530 and a controller module 535. In some embodiments,all of the modules of the image capture module 330 are implemented inhardware (e.g., ASIC, FPGA, SOC with a microcontroller, etc.), while inother embodiments, some or all of the modules of the image capturemodule 330 are implemented in software.

The sensor module 515 communicatively couples to a sensor interface 510and a camera sensor 505 of the device's camera. In some embodiments, thecamera sensor 505 is a CMOS sensor and the sensor interface 510 is partof the camera sensor 505. The communicative coupling between the sensormodule and the camera sensor/sensor interface is facilitated through anynumber of known sensor interfaces. Through this communicative coupling,the sensor module 515 can forward instructions to the camera to controlvarious aspects of the camera's operations such as its power level, zoomlevel, focus, exposure level, etc. In some embodiments, theseinstructions typically originate from the controller module 535. Also,through its communicative coupling with the camera, the sensor module515 can direct the camera sensor to start capturing images when theimage processing module 325 requests the camera to start capturingimages and the sensor module 515 receives this request through thecontroller module 535, as further described below.

In some embodiments, Bayer filters are superimposed over the camerasensor and thus the camera sensor outputs Bayer pattern images, whichare stored in the sensor interface associated with the camera sensor. ABayer pattern image is an image where each pixel only stores one colorvalue: red, blue, or green. Through its coupling with the sensorinterface 510, the sensor module 515 retrieves raw Bayer pattern imagesstored in the camera sensor interface 510. By controlling the rate atwhich the sensor module 515 retrieves images from a camera's sensorinterface, the sensor module 515 can control the frame rate of theimages that are being captured by a particular camera.

The sensor module 515 stores images that it retrieves from the sensorinterface 510 in the frame buffer 520. The images stored in the framebuffer 520 are raw, unprocessed images. Before the image processingmodule 325 can process these images, the image processing pipeline 525of the image capture module 330 needs to perform several pre-processingoperations on them. Different embodiments perform different sets ofpre-processing operations. For instance, in some embodiments, the imageprocessing pipeline 525 includes a demosaicing module (not shown) thatreconstructs a red, green, blue (RGB) image from a Bayer pattern imagestored in the frame buffer 520, by interpolating the color values foreach set of colors in the Bayer pattern image. Also, the imageprocessing pipeline 525 of some embodiments includes a color spaceconversion module (not shown) that converts the RGB image to a Y′CbCrimage. Examples of other modules that are included in the imageprocessing pipeline 525 of some embodiments include modules that perform(1) bad pixel removal to attempt to correct bad pixels in the imagesretrieved from the frame buffer, (2) lens shading correction to correctfor image defects caused by the camera lens, (3) white balancecorrection to adjust colors of the image to render neutral colorscorrectly, etc. As used herein, the converting from one format toanother refers to using data from an image in one format to generate animage in a different format. In some embodiments, the new version of theimage replaces the old image; in other embodiments both the old and newversions of the image are kept.

The statistics engine 530 collects image data at various stages of theimage processing pipeline 525. Also, in different embodiments, thisengine collects data differently from different stages of the imageprocessing pipeline 525. The statistics engine 530 processes thecollected data, and, based on the processed data, adjusts the operationsof the camera sensor 505 through the controller module 535 and thesensor module 515. Examples of such operations include exposure andfocus. In some embodiments, the exposure duration is determined by acombination of the sensor integration time and the sensor/capture moduleanalog/digital gains. Although FIG. 5A shows the statistics engine 530controlling the camera sensor 505 through the controller module 535, thestatistics engine 530 in other embodiments controls the camera sensorthrough just the sensor module 515. Also, while the statistics engine530 is shown to be separate from the controller module 535, theoperation of this engine is performed by the controller module 535. Inother words, the modularization of the statistics engine in FIG. 5A is aconceptualization of a series of operations that are performed by theimage capture module 330.

The controller module 535 of some embodiments is a microcontroller thatcontrols the operation of the image capture module 330. For instance, insome embodiments, the controller module 535 instructs the camera sensor505 through the sensor module 515 to capture images. Also, in someembodiments, the controller module 535 controls (1) the operation of thecamera sensors (e.g., exposure level) through the sensor module 515, (2)the operation of the image processing pipeline 525, and (3) aflash/strobe (not shown), which is part of the mobile device of someembodiments. Instead of receiving exposure settings from the controllermodule 535, or in conjunction with these settings, the camera sensor 505or the sensor module 515 of some embodiments use default values for thecamera sensor operations.

Some embodiments of the controller module 535 process instructionsreceived from the statistics engine 530 and the capture module driver305. In some embodiments, the instructions received from the capturemodule driver 305 are instructions from the mobile device (i.e.,received from the local device) while in other embodiments theinstructions received from the capture module driver 305 areinstructions from another device. Based on the processed instructions,the controller module 535 can adjust the operation of the image capturemodule 330.

FIG. 5B illustrates the image capture module 330 of some otherembodiments of the invention. In FIG. 5B, the sensor module 515 does notcontrol the camera sensor 505 directly and does not receive commandsfrom the controller module 535. In this figure, the controller module535 controls the camera sensor 505. In FIG. 5B, sensor module 515 passesdata from the sensor interface 510 to the frame buffer 520, just as thesensor module 515 in FIG. 5A does.

FIG. 6 illustrates a process 600 that conceptually represents a seriesof operations of the image capture module 330 during an HDR imagecapture session. This process starts each time that the device entersits image-capture mode. As shown in FIG. 6, this process initiallystarts (at 605) capturing images at a particular default rate. Based onone or more qualities (e.g., a histogram or a total light level) of oneor more of the captured images, the controller module 535 in someembodiments detects (at 605) the current light condition. Based on thecurrent light condition, the controller module defines (at 605) theexposure duration for capturing a normally exposed image (referred tobelow as an EV0 image) and relays (at 605) this exposure duration to thesensor module 515. In other embodiments, control logic associated withthe camera sensor 505 or sensor module 515 detects the light conditionand defines the exposure duration for the normal exposure (referred toas the EV0 exposure). In some embodiments, this control logic includeslight detection circuits that can quantify the amount of light underwhich the device is operating.

Irrespective of where and how the normal exposure duration iscalculated, the process 600 starts to capture images at the normalexposure duration and stores the captured images in the frame buffer. Insome embodiments, the process 600 calculates the normal exposureduration repeatedly during the image-capture session to identify thenormal exposure duration as the lighting condition changes.

After 605, the controller module 535 receives (at 610) an instructionthat it has received an HDR mode command from the image processingmodule 325 through the CM driver 305 and the media exchange module 310.Based on this command, the controller module 535 computes (at 615) theexposure durations for taking an overexposed and underexposed image(taking an EV+ and EV− image) during the current lighting conditions. Insome embodiments, the controller module performs the operation 615repeatedly during the HDR-capture session to identify the overexposedand underexposed exposure duration as the lighting condition changes.

Next, at 620, the controller module 535 receives an instruction to takea picture. In response, the controller module 535 directs (at 625 and630) the sensor module to capture one overexposed image at theoverexposed duration and one underexposed image with the underexposedduration. The controller module 535 then directs (at 635) the imageprocessing pipeline 525 to retrieve the captured EV+ and EV− images fromthe frame buffer along with one or more EV0 images in the frame buffer.As mentioned above, the image capture module returns several EV0 imagesto the image processing module 325 in some embodiments, in order toallow the module 325 to select the best EV0 image for aligning with theEV+ and EV− images. Alternatively, in some embodiments, the imagecapture module 330 only returns one normally exposed image, but tries toensure that this returned image is not blurred (i.e., is sharp). Indifferent embodiments, the image capture module 330 tries to ensure thatthe image is sharp in different ways. For instance, in some embodimentswhere the device has an accelerometer and/or gyroscope, the imagecapture module uses data recorded from the accelerometer and/orgyroscope to ascertain the likelihood of the blurriness of the normallyexposed images in order to select a normally exposed image that issharp.

In different embodiments, the controller module 535 directs (at 635) theimage processing pipeline 525 to retrieve the overexposed, underexposedand normally exposed images differently. In some embodiments, thecontroller module 535 simply notifies the processing pipeline 525 thatthe overexposed and underexposed images are being captured, and theprocessing pipeline 525 retrieves the correct images from the framebuffer 520.

The image processing pipeline 525 pre-processes (at 640) each imageretrieved from the frame buffer 520. The image capture module 330returns (at 640) each retrieved and pre-processed image to the imageprocessing module 325 for HDR image generation. After 640, the processends if the device is no longer in the HDR-capture mode, or returns to620 to wait for another “take picture” command.

The above description identifies the captured images as the source(s) ofinformation about lighting conditions. However, in some embodiments, thecamera sensor 505 determines the lighting conditions without generatingimage data. The mobile devices of some embodiments use additionalsensors instead of or in addition to the camera sensor 505 to determinethe lighting conditions.

IV. Image Alignment

A. Introduction

In order to make a composite image out of three images taken of a sceneby a mobile device, the pixels in each image that show a particular partof the scene must be composited with the pixels in each of the otherimages that show that same part of the scene. If the mobile device doesnot move while the images are being taken, then the pixels thatrepresent a particular part of a scene in each image will have the samecoordinates in the image as the pixels that represent the same part ofthe scene in each of the other images. Such images can be characterizedas aligned. However, if the mobile device moves during the taking of theimages, the pixels that represent a particular part of a scene in oneimage will have slightly different coordinates than the pixels thatrepresent the same part of the scene in the other images. In otherwords, images taken by a moving device will be out of alignment.

Before compositing the images, some embodiments compensate for themovement of the mobile device by aligning the images before compositingthem. That is, the number of pixels by which the raw images are offsetfrom each other in vertical and in horizontal directions are determinedso that the mobile device can then combine pixels from each image thatcorrespond to the same part of the scene even though the correspondingpixels do not have the same coordinates in each of the raw images. Theoffset that aligns corresponding pixels in two images can becharacterized as an offset vector, measured in pixels.

An offset between two images taken of the same scene can be caused byrotation or translation of the mobile device while the images are taken.When a user commands a mobile device of some embodiments to take a highdynamic range picture, the mobile device takes three images in quicksuccession with very little time between taking each image. However,despite the small time between taking each of the images, the handheldmobile device will most likely move slightly in the course of taking thethree images. For example, the action of touching the mobile device tocommand it to take an HDR picture can move the device. Because of themovement of the mobile device, each image will be taken from a slightlydifferent position. Because of the slight changes in position, the rawimages will not be aligned with each other. Before the high-dynamicrange process can composite the images taken at different exposures, theimages must be aligned with each other (e.g., by the mobile device) bydiscovering the specific offset vectors that will bring the images intoalignment. Such alignments are part of a process sometimes called“registration”.

The number of pixels that an image is offset from another depends on howfar the camera moves (by translation and rotation) while taking theimages and the scale of the images (e.g., how many centimeters ordegrees of the scene are represented by each pixel in an image). Forinstance, the camera's rotation or translation movement might cause twoimages of the scene to be 10 cm out of alignment (e.g., one image shows10 cm more of the left side of the scene and 10 cm less of the rightside of the scene than the other image). In such a case, if the scale ofthe images equates the length of 1 pixel in an image to 1 cm in thescene, then the images will be 10 pixels out of alignment. This scale isprovided to explain how a change in position of the image relative toreal world items in the scene can translate to a change in the imagerelative to the pixels that make up the image. In some embodiments, themobile device does not measure the actual scale of the image.

The mobile device of some embodiments does not have an exact measure ofhow far the device has moved in the course of taking the picture.Therefore, the offset that will align the images in such embodiments isunknown when the images are taken. The mobile device of some embodimentswill identify offsets that align two images by testing a range of offsetvectors. The set of offset vectors in the range tested by a mobiledevice to determine whether they align a given pair of images isreferred to herein as “potential offset vectors” or “potential offsets”.The mobile device of some embodiments determines which potential offsetvector will align the images by comparing the images (or bitmaps derivedfrom the images) at different values of the offset vectors. The range ofthe potential offsets is limited in some embodiments to those offsetsthat would leave a substantial overlap between the images. Offsets thatwould not leave a substantial overlap are not tested in such embodimentsbecause the compositing process works primarily on the overlappingportions of the images. The movement of a mobile device in the hands ofa user who is trying to hold it steady while taking a picture is likelyto be relatively small; therefore the aligning offset is often smallrelative to the size of the images. However, some embodiments test alarger range of offsets just in case the movement was larger than usual.In some embodiments, one or more external sensors (e.g., gyroscopes,motion sensors, etc.) are used to estimate the displacement and/orrotation of the mobile device. Such an estimate is used in someembodiments to determine a starting point for searching for offsetvectors. In some embodiments the estimate is used to determine a rangeof offset vectors to search (e.g., if the mobile device is held verysteady, the search range is narrower than if the mobile device is heldless steady).

Even in embodiments that limit the range of potential offsets to thosethat leave a substantial overlap between the images, the number ofpotential offsets can be large. For example, if the potential offsetsrange from 0% to 6.4% of the width and height of an image that is 1000pixels square, the potential offset vector could be between 0 and 64pixels in any direction (up, down, left, or right). With that range ofpossible offset vectors, the total number of possible offset vectors isabout 16,000 (approximately 128 vertical pixels by 128 horizontalpixels). When there are thousands of potential offset vectors to test,testing the potential offset vectors by directly comparing large images(or large bitmaps) at each possible offset vector requires a very largenumber of calculations.

To reduce the number of calculations performed to find the actualoffset, some embodiments perform a hierarchical alignment process. Thehierarchical alignment process of some embodiments generates versions ofthe images at lower resolutions. The lower resolution image contains thesame scene, but with a larger scaling factor. For example, if a1000×1000 (pixel×pixel) image represents a scene that is 10 m wide, thenone pixel length in the image represents 1 cm in the scene. One pixellength in a 500×500 resolution image generated from the 1000×1000 imagerepresents 2 cm in the scene. Similarly, one pixel length in a 250×250resolution image generated from the 500×500 image represents 4 cm in thescene.

Because of the difference in scale (i.e., fewer pixels representing thesame scene), the potential offset vectors at lower resolutions cover thesame fraction of the image, but the absolute number of potential offsetvectors is smaller. In the above example, dropping the resolution by afactor of four (from 1000 pixels square to 250 pixels square) wouldreduce the range of possible offsets from plus or minus 64 pixels toplus or minus 16 pixels (i.e., 64 pixels divided by 4). Such a reductiondecreases the number of possible offset vectors by a factor of 16 (i.e.,from about 16,000 possible offset vectors to about 1,000 possible offsetvectors). Such a process finds the offset vector by starting with afirst approximation and then determining the actual offset vectorthrough successively finer approximations.

The processes of some embodiments calculate the successiveapproximations of an offset vector that aligns two images by generatingreduced resolution versions of the raw images, generating 1-bit bitmapsfrom the lower resolution versions of the images, and aligning thebitmaps. The bitmaps are aligned starting with the lowest resolutionbitmaps. To align the bitmaps, the processes compare two bitmaps to eachother using various test offset vectors to determine the actual offsetvector between the bitmaps. The processes of some embodiments compare asubset of the pixels in the bitmaps rather than comparing all the pixelsin the bitmaps. In some such embodiments, before comparing two bitmaps,the processes divide one or both bitmaps into tiles and discards tilesthat contain more than a threshold percentage of black pixels or morethan a threshold percentage of white pixels. Such processes then comparethe pixels in the remaining tiles to determine the offset vector betweenthe bitmaps. The offset vector identified for each resolution of bitmapsis used as a starting point for testing offset vectors for the nexthigher resolution of bitmaps. These processes are further described inrelation to FIGS. 7-11, below.

B. Production of Bitmaps for Alignment

Some embodiments produce multiple bitmaps to be used to search for theoffset vector that will align two images. FIG. 7 illustrates a process700 of some embodiments for generating such a series of bitmaps foraligning images. As used herein, the term “bitmap” refers to a versionof an image with a color depth of one bit per pixel. Each pixel in sucha bitmap can be represented as either black or white.

The process 700 receives (at 710) an original image. In someembodiments, the images are received from the camera of the mobiledevice. The camera operations of the mobile device of some embodimentsare controlled by a program that is independent of a program thatperforms process 700. In some such embodiments, the image is receivedfrom the program that controls the camera operations. In otherembodiments, a single program controls both the camera operations andperforms the process 700. In some such operations the program that isimplementing both the bitmap generation process 700 and the cameraoperations of the mobile device receives the images from the camerahardware. The programs of some embodiments receive images from a memoryof the mobile device instead of or in addition to receiving images fromthe camera hardware. Different embodiments of the mobile device providethe image in different formats. In some embodiments, the images arerepresented in terms of a brightness value and a set of color values foreach pixel. For instance, in some embodiments, the process receives theimages in a Y′CbCr (luma, blue-chroma, and red-chroma) format. In someembodiments, the images are represented in terms of different colorcomponent values. Instead of or in addition to providing images in aluma/chroma format, the mobile device of some embodiments providesimages in terms of different color component values. The color componentvalues of some embodiments are provided in an RGB format (e.g., an sRGBimage). In such embodiments, the process 700 converts the images to aluma image as part of the receiving operation.

The process decimates (at 720) the original luma image. The decimationof the original image creates a copy of the image at one half theresolution (in each dimension) of the original. For example, if theoriginal image has a resolution of 1920×1280, the copy will have aresolution of 960×640.

The process 700 performs the decimation a particular number of times togenerate a number of images with different resolution levels to use forsuccessive approximations of the offset vector, e.g., in the process ofFIGS. 9-10. Various embodiments decimate the images various numbers oftimes. In some embodiments, the number of decimations affects the rangeof potential offsets. The lower the resolution of a given image, thefewer the number of potential offset vectors there are for a givenpercentage of the image. Accordingly, in some embodiments, the largerthe range of potential offsets to be tested, the more levels ofdecimation are used. The number of levels of decimation ispre-programmed in some embodiments. For example, some embodimentsprovide an original image and five levels of decimation, with the lowestresolution decimated image being 1/32nd of the resolution of theoriginal image (in each dimension) and having 1/1024th the number ofpixels. Some embodiments provide an original image and six levels ofdecimation, with the lowest resolution decimated image being 1/64th ofthe resolution of the original image (in each dimension) and having1/4096th the number of pixels. The decrease in the resolution results ina corresponding decrease in the number of potential offset vectors in agiven fraction of the image. Therefore, a 1 to 4096 reduction in thenumber of pixels decreases the number of potential offset vectors in agiven fraction of the image by a factor of 4096.

The number of decimations is preset in some embodiments. However, localconditions, such as a shaky hand or low light levels, can affect themotion of the mobile device. Therefore, in addition to or instead ofusing a pre-set (default) number of decimations, some embodiments allowthe user to determine the number of decimation levels or have the mobiledevice determine the number of decimation levels dynamically in responseto one or more variables available at the times that the original imagesare taken. For example, when taking the three HDR images with longertotal exposure times (e.g., in low light conditions) the user's hand hasmore time to move, and thus can move farther at the same speed. Someembodiments compensate for the additional movement by increasing thelevels of decimation to compensate for the additional time to move. Themobile devices of some embodiments include motion sensors that provideat least some indication of how fast the user's hands are moving. Insome such embodiments, faster motion of the mobile device during thecapture of the images prompts the mobile device to produce moredecimation levels.

Regardless of how the number of decimations is determined, there are afinite number of decimations. Accordingly, the process determines (at730) whether the decimation has been repeated enough times to generatethe desired number of decimated images. If the decimation has not beenrepeated enough times then the process returns to 720 to decimate theimage produced in the previous round of decimation. Each repetition ofthe decimation (at 720) produces a new copy of the image at successivelysmaller resolutions. For example, if the decimation is performed sixtimes starting from an original image with a resolution of 1920×1280,then the total number of images would be seven (including the originalimage) with resolutions 1920×1280 (original), 960×640 (first decimatedimage), 480×320 (second decimated image), 240×160 (third decimatedimage), 120×80 (fourth decimated image), 60×40 (fifth decimated image)and, 30×20 (sixth decimated image).

The decimation in some embodiments is performed by any known method ofdecimating images. For example, some embodiments use one or more of thefollowing techniques: (1) grouping the pixels into n-by-n squares, wheren is the decimation factor (e.g., 2) then averaging the values of thepixels in the squares, (2) a moving average filter, (3) a weightedmoving average filter, (4) selecting one pixel value in every n-by-ngroup (e.g., the median pixel value or the pixel value at a particularlocation in the group, (5) using a least squares analysis technique, (6)sub-sampling, and (7) other decimation methods.

Once the process 700 determines (at 730) that the correct number ofdecimated images has been produced, from each image (i.e., the originalluma image and each image resulting from the decimations), the processgenerates a 1-bit bitmap. Bitmap images are generated from the imagesbecause finding an offset between two bitmaps is computationally lessintense than directly finding an offset between the images themselves.The operations of some embodiments for generating bitmaps compensate fordifferences in luma values that result from the different exposurelevels of images to be compared. Despite the different luma values ineach exposure, each exposure will show the brighter parts of the sceneas being brighter than the darker parts of the scene. More specifically,the lighter (and darker) half of the pixels in one exposure will be aclose match in shapes and positions for the lighter (and darker) half ofthe pixels in the other exposure. The median luma value of each image isused to separate the brighter half of the pixels in that image from thedarker half of the pixels in that image. The median luma value of animage is the luma value for which half the pixels in the image have alower luma value (or the same luma value) and half the pixels in theimage have a higher luma value (or the same luma value). Therefore, athreshold operation performed on each image using the median luma valueof that image will generate a bitmap that is approximately the same asthe bitmaps produced by the other images, regardless of the differentexposure times.

Accordingly, to prepare for the generation of a bitmap from a lumaimage, the process 700 identifies (at 740) a median luma value for eachimage (including the original and all decimated images). The median lumavalue will be used to generate the bitmaps. As mentioned above, by usingthe individual median luma value for each image, the alignment process700 compensates for the different range of luma values in the differingexposures. One of ordinary skill in the art will understand that someembodiments might use other methods for generating the bitmaps. Forexample, the threshold of some embodiments is derived from the medianluma value (e.g., the threshold is the median luma value divided by 2),but is not the median luma value. The threshold of some otherembodiments is determined from some other characteristic of the image(e.g., the threshold is the mean of the luma range rather than themedian of the lumas).

The process then generates (at 750) a 1-bit bitmap version of each imageby performing a threshold operation using the median luma value of thatimage as the threshold value. A threshold operation on a pixel in a lumaimage generates a corresponding pixel in the bitmap. The thresholdoperation generates a white pixel in the bitmap if the correspondingpixel in the image is lighter than the threshold luma value andgenerates a black pixel in the bitmap if the corresponding pixel in theimage is darker than the threshold luma value. Because the thresholdluma value used in this operation is the median luma value of the imageused to generate the bitmap, approximately half of the pixels in thebitmaps will be black and approximately half of the pixels will bewhite. The process 700 then ends.

The process 700 was described above as including several features. Oneof ordinary skill in the art will understand that not all of thefeatures described above are found in every embodiment. Also, variousembodiments of process 700 have other features in addition to or insteadof one or more of the features described above. One of ordinary skill inthe art will realize that some individual embodiments include multiplefeatures that are implemented as alternatives to each other rather thanimplemented in the same operation. For example, the above describedprocess acts on luma images. However, one of ordinary skill in the artwill understand that some embodiments use luminance images (theluminance component of a YCbCr image) instead of luma images. Stillother embodiments use luma images in some cases and use luminance imagesas an alternative in other cases. The above described process generatesa separate bitmap from a luma image, but in some embodiments, a bitmapoverwrites the corresponding luma image. The decimated images in someembodiments are overwritten during the bitmap generation process ordeleted after their respective bitmaps have been generated in order tosave memory.

Although the above described process 700 generates the bitmaps from thedecimated images after all the decimated images have been produced, oneof ordinary skill in the art will understand that some embodimentsgenerate a bitmap from a decimated image after the decimated image isproduced, but before all the decimated images have been produced. Theabove described embodiments decimate the images by a factor of 2.However, one of ordinary skill in the art will understand that someembodiments decimate the images by factors other than 2. In the abovedescribed process, each decimated image is generated from the nexthighest resolution decimated image. However, in some embodiments,decimated images are generated using images other than the next highestresolution decimated image (e.g., a decimated image can be produced fromthe original luma image or from a decimated image two resolution levelsup). In the process described above, a black pixel in the bitmapcorresponds to a darker-than-the-median pixel in the luma image and awhite pixel in the bitmap corresponds to a lighter-than-the-median pixelin the luma image. However, one of ordinary skill in the art willunderstand that “black” and “white” represents an arbitrary choice ofcolors to represent two possible binary values of a pixel in the bitmap.In some embodiments, a darker pixel in the image will be represented inthe bitmap as a binary value “0” and a lighter pixel in the image willbe represented in the bitmap as a binary value “1”. In otherembodiments, a darker pixel in the image will be represented in thebitmap as a binary value “1” and a lighter pixel in the image will berepresented in the bitmap as a binary value “0”.

FIG. 8 illustrates examples of bitmaps of some embodiments that can beused to search for alignments. The bitmaps have been generated from animage of a car. The bitmaps in FIG. 8 are not drawn to scale. The figureincludes original images 800 and 805, bitmaps 810A-810C and 815A-815C,and tiled bitmaps 820 and 825. Original image 800 is an image taken witha medium duration exposure from the mobile device. Original image 805 isan image from the same mobile device taken with a shorter durationexposure. Bitmaps 810A-810C are bitmaps generated from copies (withdifferent resolutions) of original image 800. Bitmaps 815A-815C arebitmaps generated from copies (with different resolutions) of originalimage 805. Tiled bitmap 820 is a copy of bitmap 810C that has beenconceptually divided into tiles. Tiled bitmap 825 is a copy of bitmap815C that has been conceptually divided into tiles.

The bitmaps in this figure with the same resolution can be compared toeach other to search for the offset of the original images 800 and 805.The offset of images 800 and 805 is a vector that, when applied to oneof the images, causes it to align with the other image. In this case,the car in image 800 is closer to the right side of its image while thecar in image 805 is closer to the left side of its image. Therefore,applying an offset to image 805 that moved its pixels to the right bythe correct amount would align it with image 800.

The bitmaps 810A and 815A are offset by the same amount as the images800 and 805 because bitmaps 810A and 815A were generated directly fromthe original images. The offset of images 800 and 805 could be found byfinding the offset of bitmaps 810A and 815A. However, finding the offsetof bitmaps 810A and 815C simply by trying every possible offset to seeif it aligns the bitmaps would be computationally expensive because ofthe large number of possible offsets to be checked to align two highresolution bitmaps. Therefore, the processes of some embodiments searchfor the correct alignment via a hierarchical process of successiveapproximations rather than trying all possible offset vectors for thehigh resolution bitmaps.

The lowered resolution of the bitmaps 810C and 815C results in fewerpossible offsets to check when aligning bitmaps 810C and 815C. However,the lower number of possible offsets to check also means less accuracyin the offset found at that resolution. Specifically, an offset of onepixel between bitmaps 810C and 815C represents an offset of severalpixels (e.g. 64 pixels) between original images 800 and 805, so anoffset that aligns bitmaps 810C and 815C will not precisely specify anoffset that align bitmaps 810A and 815A. However, an offset that alignsbitmaps 810C and 815C can be used as a first approximation of the offsetthat aligns bitmaps 810A and 815A. The offset that aligns bitmaps 810Cand 815C is a starting point in the hierarchical process for findingoffsets of higher resolution bitmaps.

The sets of successively larger bitmaps allow the value for the offsetto be refined using each successively higher resolution bitmap. In FIG.8, each consecutive bitmap in a given column of bitmaps conceptuallyrepresents a bitmap generated from an image with half the resolution ofthe image used to generate the previous bitmap in the column, so theoffset of each bitmap is half the offset of the next highest resolution.For example, bitmap 810A was generated from an original image 800 withresolution 1920×1280 (original) and bitmap 810B was generated from adecimated copy (not shown) of original image 800 with resolution 960×640(the first decimated image). An offset of 10 pixels to the right betweenbitmaps 810B and 815B represents an offset of 20 pixels (plus or minusone pixel) to the right between bitmaps 810A and 815A. When the offsetfor the larger resolution bitmaps 810A and 815A is found, the startingpoint for the search would be 20 pixels to the right. As furtherdescribed with respect to FIGS. 9-11, below, the alignment process wouldthen evaluate possible offsets within one pixel of the starting point tosearch for the actual offset at 19 pixels, 20 pixels, and 21 pixels tothe right.

In FIG. 8, the ellipsis between bitmap 810B and 810C elides bitmaps ofsuccessively smaller resolutions, generated from decimated images eachwith half the resolution (in each dimension) of the preceding decimatedimage. As described with respect to FIG. 7, the decimation andgeneration of bitmaps continues for some particular number of levels ofresolution (e.g., six levels). In FIG. 8, the bitmaps 810A-810C and815A-815C and the original images 800 and 805 are not drawn to scale.

The embodiments described above generate each bitmap from a decimatedimage with the same resolution as the generated bitmap. Alternatively,in some embodiments a bitmap of a lower resolution can be generated froma higher resolution bitmap instead of from a decimated image. Generatingbitmaps from higher resolution bitmaps is faster in some embodimentsthan generating bitmaps from decimated images. However, generatingbitmaps from higher resolution bitmaps instead of from decimated imagestends to generate artifacts in the bitmaps that can reduce theefficiency and/or accuracy of searches for offset vectors. Thereforethis technique is not used in all embodiments.

Some embodiments align bitmaps by dividing one or both bitmaps intotiles and comparing the pixels in some or all of the tiles tocorresponding pixels in the other bitmap to find an offset vector thatcauses the features of each image to line up. The short descriptionbelow is for an embodiment that tiles one bitmap at each resolution.

The process of some embodiments compares the two bitmap images multipletimes using multiple test offset vectors. The comparison systematicallycompares pixels in one bitmap (the “tiled bitmap”) with thecorresponding pixel in a second bitmap (the “target bitmap”). Theprocess compares pixels in the tiled bitmap with pixels in the targetbitmap that are offset by the offset vector. For each test offsetvector, the process of some embodiments counts the number ofcorresponding pixels that are different from each other. The closer thetest offset vector is to the actual offset between the two images, thesmaller the number of pixels in the two bitmaps that are different fromthe tiled bitmap to the (shifted) target bitmap.

Some bitmaps generated from decimated images include tiles that arealmost all black or almost all white. The omission of the tiles that areall black, almost all black, all white, or almost all white from thecomparison speeds up the comparison without changing the identifiedoffset vector in some embodiments. Therefore, some embodiments discardthe black, almost all black, white, and almost all white tiles from thecomparison.

Accordingly, the bitmaps of some embodiments are conceptually dividedinto tiles, such as tiled bitmaps 820 and 825, as part of a process(described in relation to FIGS. 9 and 10, below) for finding the offsetvector. The each tile contains a number of pixels. In the process ofsome embodiments for finding the offset vector of two bitmaps, tilesthat are all black or almost all black (e.g., the top half of the frontwheel in tiled bitmap 820) with less than some threshold number of whitetiles are ignored and tiles that are all white (e.g., the left and topedge tiles of tiled bitmap 820) or almost all white (e.g., the frontwindshield of tiled bitmap 820) with less than some threshold number ofblack tiles are ignored. That is, the pixels within those tiles are notincluded in the comparisons of the two bitmaps that are made whilesearching for an offset vector that brings those two bitmaps intoalignment.

C. Hierarchical Alignment of Images

Once bitmaps are produced in multiple resolutions, some embodiments usethe bitmaps to find offset vectors that align the images. FIGS. 9-10illustrate a process 900 and a process 1000 of some embodiments forfinding an offset vector that aligns two images. For clarity, thedescription of process 900 describes the alignment of two images witheach other. However, in some embodiments, the process 900 receives threesets of bitmaps for the three original images of different exposures andaligns the three images. In aligning the three images, the process 900first aligns two images and then aligns the third image with one of theother two images. Process 900 is a hierarchical process that finds theoffset between two images by finding a gross approximation for theoffset using a low resolution bitmap then narrows in on the actualoffset value by finding successively closer approximations to the actualoffset vector using successively larger resolution bitmaps. The processtests nine candidate offset vectors at each resolution to find whichoffset vector brings the bitmaps closest to alignment at thatresolution.

FIGS. 9-10 will be described with references to FIG. 11. FIG. 11illustrates an example of finding an offset vector that aligns twoimages in some embodiments. This figure shows, one hierarchical level ata time, how an offset vector between two images is found by process 900.The figure includes rows/stages 1110-1140 and columns 1165-1180. Each ofthe stages 1110-1140 conceptually represents a hierarchical level in theidentification of an offset vector between two images. Each of thecolumns 1165-1180 represents a significant feature of each stage. Thestages 1110-1140 each include a decimated resolution (in column 1165), astarting offset vector (in column 1170), an identified addition to theoffset vector (in column 1175), and a new offset vector (in column1180).

The decimated resolution values of column 1165 identify the resolutionof the bitmaps to be compared in each stage. This conceptuallyillustrates the selection of resolutions in process 900 (at 920 and970). The starting offset vectors of column 1170 represent an offsetvector that acts as an origin around which the candidate vectors will betested. Each row of column 1175 includes nine candidate vectors. Thearrows (and circle) in the various stages of column 1175 conceptuallyillustrate a candidate vector selected by process 1000 as the candidateoffset vector that produces the best alignment of the bitmaps at thatresolution. The new offset vectors of column 1180 represent the vectorsums of the starting offset vector and the vector identified in column1175 in the same stage. The offset vector in column 1180, in the finalstage 1140 represents the offset of the two original, full resolutionimages.

In some embodiments, the process 900 uses bitmaps produced by a processsuch as process 700 of FIG. 7. The process 900 begins by receiving (at910) two sets of bitmaps. Each set of bitmaps has been generated from anoriginal image from the mobile device. The received sets of bitmapsinclude a range of resolutions each a factor of two smaller than thenext larger resolution. The process 900 selects (at 920) the lowestresolution bitmaps as the current pair of bitmaps to work with (e.g., tofind an offset vector that aligns the bitmaps). In the example in FIG.11, stage 1110 represents the lowest hierarchical level. The resolutionof the bitmap in stage 1110 is 30×20, as shown in column 1165.

As described above in relation to tiled bitmaps 820 and 825, the bitmapscan be conceptually divided into tiles. The process 900 divides (at 930)the current bitmap in each set into tiles. Some embodiments only divideone bitmap in each pair of bitmaps (with a common resolution) intotiles. Each tile contains a particular set of pixels. In this context, atile is considered to contain a pixel when the pixel is within a rangeof locations identified by that tile. For example, using the lower leftpixel of a bitmap as coordinate (0, 0), a particular tile could includeall tiles with x-coordinates between 10 pixels and 19 pixels andy-coordinates between 20 pixels and 29 pixels. A pixel with coordinates(13, 25) would be a pixel in that tile and a pixel with coordinates (22,25) would be a pixel in a different tile. One of ordinary skill in theart will understand that tiles can be different sizes in differentembodiments and could even be different sizes in the same embodiments.For example, tiles in different resolutions could be different sizes.Tiles of some embodiments are different sizes relative to the resolutionof the bitmaps.

Some tiles contain a significant number of both black pixels and whitepixels. Other tiles contain all (or almost all) black pixels or all (oralmost all) white pixels. To speed up later comparisons that find theoffset vector that aligns two tiles, the process of some embodimentsdiscards (at 940) all tiles that contain mostly one color of pixels(black or white). That is, when performing later comparisons to find howwell a candidate offset vector aligns the two bitmaps, the process 900will not include the pixels from the discarded tiles in thosecomparisons. In some embodiments, tiles are discarded if they have lessthan a threshold number of the minority color. The threshold number insome embodiments is 5% of the total number of pixels in the tile. Inother embodiments, the threshold number of the minority color is someother percentage of the pixels in the tile. Only one of the pair ofbitmaps has tiles discarded in some embodiments. In other embodiments,tiles are discarded from both bitmaps.

The process 900 identifies (at 950) an offset vector for aligning thetwo bitmaps of the current resolution. Operation 950 for finding theoffset vector is described further as process 1000 of FIG. 10. FIG. 11conceptually illustrates operation 950 in column 1175. For example, asshown in column 1175, stage 1110, operation 950 evaluates all vectorswithin one pixel of the origin to find the offset vector that providesthe closest alignment between the bitmaps at this resolution (30×20).The arrow in column 1175 at stage 1110 indicates that the closestalignment is generated by offset (1, 1). In the lowest resolution stage1110, operation 950 aligns bitmaps that are 1/64th the resolution (ineach dimension) of the original image. The values of the identifiedoffset vectors double at each stage, therefore the contribution of acandidate offset vector in one stage doubles in every subsequent stage.For example, the selected candidate offset vector in stage 1110, column1180 is (1, 1). This vector doubles in each subsequent stage (6 times),making its total contribution to the final offset vector (64, 64).Similarly, the selected candidate offset vector in stage 1120 (−1, −1)doubles 4 times making its total contribution to the final offset vectora vector of (−16, −16).

Effectively, in terms of the actual offset vector between the fullresolution (1920×1280) images, in stage 1110, operation 950 finds thatthe offset between the two full resolution images is (64, 64) (i.e., 64times the identified offset vector). The offset (64, 64) is a roughdetermination that will be refined in the later stages. For example,operation 950 in stage 1115 could change the offset vector by 0 or ±32in each direction (vertical and horizontal); in stage 1120, it couldchange the offset vector by 0 or ±16 in each direction, and so on untilstage 1140 that can change the offset vector by 0 or ±1 in eachdirection. Accordingly, assuming a full range of possible offsets in thelater stage, rather than the specific offset vectors shown in FIG. 11,given an offset of (1, 1) at the lowest resolution, in later stages,operation 950 could find a final offset for the images of between 1 and127 pixels in the horizontal direction and between 1 and 127 pixels inthe vertical direction. Similarly, in stage 1115, operation 950 alignsbitmaps that are 1/32nd the resolution (in each dimension) of the actualimage. In terms of the actual offset vector between the full resolution(1920×1280) images, in stage 1115, operation 950 finds that the offsetbetween the two full resolution images is (96, 64) (i.e., 32 times theidentified offset vector). The offset (96, 64) is still a roughdetermination that will be refined in the later stages 1120-1140. Thelater stages could adjust either value of the vector up or down by up to31 pixels. Assuming a full range of possible offsets in the later stage,rather than the specific offset vectors shown in FIG. 11, given that theoffset is (3, 2) at this resolution (60×40) the process 900 in the laterstages could find a final offset for the images of between 33 and 95pixels in the horizontal direction and between 65 and 127 pixels in thevertical direction.

Once an offset vector has been found at a given resolution, process 900determines (at 960) whether more bitmaps remain to be aligned. If theprocess determines (at 960) that more bitmaps need to be evaluated, thenthe process selects (at 970) the next lowest resolution bitmap as thecurrent bitmap. For example, in FIG. 11, after stage 1110, operation 970selects the next lowest resolution bitmaps, 60×40. The process thendoubles (at 980) the offset vector identified in operation 950 to use asa starting point for evaluating candidate offset vectors for the bitmapswith the new resolution. For example, in FIG. 11, the offset vector(1, 1) in stage 1110, column 1180 is doubled from (1, 1) to (2, 2) incolumn 1170 of stage 1115. In each stage, the starting offset vector istwice the new offset vector from the preceding stage to account for thefact that the resolution of a stage is twice the resolution of thepreceding stage. Effectively, every coordinate of the bitmap doublesfrom one resolution to the next and the new starting offset vectordoubles accordingly.

If the process determines (at 960) that no more bitmaps need to beevaluated (i.e., when the most recently compared bitmaps were the fullresolution bitmaps), the process 900 has found the offset vector thatwill align the two original images. For example, in FIG. 11, after stage1140, there are no more bitmaps to evaluate. Accordingly, the offsetvector in stage 1140, column 1180, specifically (87, 48) is the offsetvector that aligns the two images. With the images successfully aligned,the process 900 then ends.

As mentioned above, operation 950, which aligns a particular pair ofbitmaps at a given resolution is shown in more detail in FIG. 10. FIG.10 illustrates a process 1000 for finding an offset vector for aligningtwo bitmaps. The process 1000 compares pixels of the two bitmaps, asshifted by various candidate offset vectors (and a starting offsetvector, if any), and finds which candidate offset vector produces theclosest alignment. The process 1000 is part of process 900 of someembodiments.

The process 1000 selects (at 1010) a candidate offset vector. Thecandidate offset vector is a vector selected from a set of possibleoffset vectors. The possible offset vectors are all vectors offset fromthe origin by zero or plus or minus one pixel vertically and by zero orplus or minus one pixel horizontally. The candidate offset vectors are(−1, −1), (−1, 0), (−1, 1), (0, −1), (0, 0), (0, 1), (1, −1), (1, 0),and (1, 1). The candidate offset vectors are illustrated in column 1175of FIG. 11.

The process adds (at 1020) the candidate offset vector to a startingoffset vector to generate a combined vector. The starting offset vectoris the offset vector found by process 1000 as aligning the bitmaps ofthe previous resolution (if any). In FIG. 11, in stage 1110, the lowestresolution bitmaps are aligned. There is no previous resolution, so thestarting offset vector is (0, 0). In the first stage with a non-zerostarting offset vector (i.e., stage 1115) the process 1000 evaluates allpossible offset vectors within one pixel of the starting offset vector(2, 2). That is, in stage 1115, the process 1000 tests vectors (1, 1),(1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), and (3, 3).

As mentioned above, the arrows (and the circle in stage 1130) in column1175 conceptually identify which candidate offset vector produces theleast number of differences when comparing the two bitmaps in theexample shown in FIG. 11. The arrow in column 1175 in stage 1115indicates that the closest alignment is generated when candidate offsetvector (1, 0) is added to the starting offset vector (2, 2). Whencandidate offset vector (1, 0) is added to starting offset vector (2,2), the result is an offset vector (3, 2), as shown in column 1180 instage 1115.

The process then compares (at 1030) the two bitmaps using the combinedvector as a test offset vector. The comparison systematically compareseach pixel in every non-discarded tile in the tiled bitmap with thecorresponding pixel in the target bitmap. The corresponding pixel in thetarget bitmap is the pixel whose coordinates in the target bitmap areoffset by the test offset vector from the coordinates of the pixel inthe tiled bitmap. For example, with a test offset vector of (25, 30), apixel at coordinates (x, y) of the tiled bitmap will be compared to apixel at coordinates (x+25, y+30) of the target bitmap. An XOR operationis used in some embodiments to compare two 1-bit values (e.g., thevalues of pixels in the two bitmaps) to find out whether they aredifferent from each other. If the pixels being compared are different(i.e., one pixel is black and the other pixel is white), then the XORoperation produces an output of one, if the pixels are the same (i.e.,both pixels are black or both pixels are white), then the XOR operationproduces an output of zero. For each test offset vector, the process1000 of some embodiments counts the number of corresponding pixels thatare different from each other. The closer the test offset vector is tothe actual offset between the two bitmaps, the smaller the number ofpixels in the two bitmaps that are different from the tiled bitmap tothe (shifted) target bitmap.

In comparing the bitmaps by counting how many pixels are different fromone bitmap to the (shifted) other bitmap, the process 1000 of someembodiments does not include the pixels in the discarded tiles in thecomparison. Only pixels that are in tiles with a significant presence(e.g., more than 5% in some embodiments) of both black and while pixelsare included in the comparisons. In some embodiments that discard tilesfrom only one of the bitmaps, the non-discarded tiles from the tiledbitmap specify which pixels will be compared. For example, with a testoffset vector of (25, 30), a pixel at coordinates (x, y) of the tiledbitmap will usually be compared to a pixel at coordinates (x+25, y+30)of the target bitmap. However, if coordinates (x, y) lie within adiscarded tile of the tiled bitmap the pixel of the tiled bitmap atthose coordinates will not be compared with any pixel of the targetbitmap. In other words, when the coordinates (x, y) lie within adiscarded tile of the tiled bitmap, then the process of some embodimentswill simply not run a comparison of the pixel at (x, y) of the tiledbitmap with the pixel at (x+25, y+30) of the target bitmap or any otherpixel of the target bitmap.

In some embodiments, the reason for discarding the tiles that are almostall black or almost all white is that those tiles do not significantlyaffect the results. For example, if an all white tile is in an all whiteregion, then any small offset would align the white pixels in that tilewith another set of all white pixels in the corresponding region of theother bitmap. If each of the candidate vectors would cause that whitetile to be compared to a different set of all white pixels, thencomparisons of the pixels in the white tile with corresponding pixels inthe target bitmap would not provide any data that could be used todifferentiate the offset vector from the other candidate vectors.

The process stores (at 1040) a value determined by the number of pixelsfound to be different from one bitmap to the other with the given testoffset vector. In some embodiments, the value is simply the number ofpixels that are different. In other embodiments, the value is not theactual number of pixels that are different, but is derived from thenumber of pixels that are different.

The process then determines (at 1050) whether more candidate vectorsneed to be evaluated. If more candidate vectors need to be evaluated,then the process returns to 1010 and selects a new candidate vector. Ifall candidate vectors have been evaluated, the process identifies (at1060) the candidate vector that provides the best alignment of thebitmaps based on the stored values for each. For example, in someembodiments, the candidate vector that resulted in the lowest number ofdifferences between the tiled bitmap and the shifted target bitmap isidentified as the candidate vector that provides the best alignment. Thebest candidate vector is added (at 1070) to the starting offset vectorto provide a new offset vector. The process 1000 then ends and process900 resumes at 960.

The next highest resolution pair of bitmaps represents the same image asthe current resolution, but at a finer scale. Because of the finerscale, the new offset vector does not identify the exact offset of thenext highest resolution pair of bitmaps. However, finding the new offsetvector that best aligns bitmaps at one resolution narrows down the rangeof offset vectors that could possibly provide the best alignment of thebitmaps at the next highest resolution. In embodiments that double theresolution at each level, the precision of an alignment at a givenresolution is only half the precision of an alignment at the nexthighest resolution. The new offset vector identified by process 1000 isaccurate to within less than one pixel at the current resolution.Accordingly, when the new offset vector is scaled up to the nextresolution (e.g., in operation 980), the uncertainty in the value of thealignment scales up as well. That is, if the next resolution is twice ashigh as the current resolution, then the starting offset vector will bewithin less than two pixels (in each direction) of the actual offset atthat resolution. The set of all offset vectors that are less than twopixels away from the starting offset vector includes nine vectors.Specifically, the nine vectors are the vector sums of the startingoffset vector and the nine candidate offset vectors.

The starting offset vector for each resolution is derived from the newoffset vector that aligns the two bitmaps at the next lowest resolution.There is no next lowest resolution for the lowest resolution bitmaps.Accordingly, the process 1000 doesn't have a starting offset vector whenit is aligning the lowest resolution bitmaps. For the lowest resolutionbitmaps, the range of possible offsets has not been narrowed, therefore,the offset vector that aligns the bitmaps at the lowest resolution maybe more than one pixel away from the starting point of the search.Accordingly, in some embodiments, the process 1000 evaluates a largerrange of candidate offset vectors for the lowest resolution bitmaps thanfor the higher resolution bitmaps.

Depending on which candidate vectors are chosen at each stage, in anembodiment with 6 levels of decimation, the possible values of theoffset vectors found by the hierarchical search of process 900 are from−127 to 127 horizontally, and −127 to 127 vertically. Each successivestage narrows down the range of possible offset vectors by approximatelya factor of two. A value of 127 for the horizontal component of theoffset will be reached if the candidate offset vector selected at eachlevel has a value of 1. In such a case, the lowest resolution levelcontributes 64 pixels to the total; the next lowest resolution levelcontributes 32 pixels to the total, and so on until the highestresolution level contributes 1 pixel to the total.

While the preceding description included 9 candidate vectors at eachresolution, one of ordinary skill in the art will understand that otherembodiments use different numbers of candidate vectors. Some embodimentsdecimate by factors other than 2. In such embodiments, the number ofcandidate vectors increases to compensate for the larger increase inresolution when going from a lower resolution to a higher resolution.For example the images are decimated by a factor of 4 in each directionin some embodiments. In some such embodiments, the starting offsetvector is scaled by a factor of 4 (from one resolution to the next) andthe candidate vectors include all vectors within 3 pixels of thestarting offset vector. Some such embodiments use 49 candidate vectors.

While the preceding description included discarding predominantly whitetiles and predominantly black tiles at every resolution level, someembodiments discard tiles only at higher resolution levels. At lowresolutions, the number of pixels in an image is smaller, so eliminatingtiles is more likely to affect the outcome of the search. Additionally,the search for offset vectors that align low resolution bitmaps isreasonably fast even without discarding tiles. Due to the increased riskof error when discarding tiles at low resolutions, and the decreasedbenefit to the speed of the search for offset vectors, some embodimentsdiscard tiles only for bitmaps above a certain resolution level. Forexample, some embodiments discard tiles only for bitmaps generated fromimages with 5 levels of decimation. Similarly, some embodiments discardtiles only for bitmaps generated from images with 4, 3, 2, 1, or 0level(s) of decimation. Some embodiments that discard tiles only forhigher resolution images do not tile the lower resolution bitmaps. Somesuch embodiments compare the entire bitmaps at low resolution levels.Some embodiments exclude pixels near one or more edges of one or more ofthe bitmaps in order to compare the same number of pixels for eachoffset.

Image Processing: HDR Image Generation and Scaling

A. Introduction

In photography, different scenes are photographed for different exposuredurations. Long exposure durations provide a high level of detail fordim objects. Short exposure durations provide a high level of detail forbright objects. However, an exposure time that is not matched to thebrightness of an object being photographed can create poor results. Forexample, when taking an image of a bright object, too long an exposureduration results in the saturation of the sensors on which the image ofthat bright object is focused. Detail is lost in that case because anylight level above the saturation level simply appears as white (with themaximum value). When all pixels appear white, the differences in lightlevels that would otherwise provide details are not captured. Anotherexample of poor results comes from taking an image of a dark object withtoo short an exposure duration. Too short an exposure duration providesinadequate light for the sensitivity of the sensors on which the imageof the dark object is focused. The detail is lost because the sensorscan't accurately identify small percentage differences in the alreadysmall amount of light received. Because different scenes look betterwith different exposure times, photographers and automatic camerasadjust exposure times to compensate for lighting conditions. The mobiledevices of some embodiments also adjust exposure times in accord withthe lighting conditions of the scenes they are photographing. Longexposure times are used to capture the detail of dark scenes; shortexposure times are used to capture the detail of bright scenes; andmedium exposure times to capture the details of scenes that are betweenbright and dark (midtones).

However, when one scene includes bright and dark objects as well asmidtone objects, an exposure time long enough to capture the details ofthe dark object will leave the bright object saturated in the image andthe midtone objects overly bright. An exposure time short enough tocapture the details of the bright object will leave the dark objectmostly black and the midtone objects too dark. An exposure time justright to catch the midtone items will leave the dark objects too darkand the bright objects too bright.

To avoid the saturation of bright objects and low detail of darkobjects, some embodiments take three images at different exposures(overexposed, underexposed and normally exposed) and composite theimages in a way that emphasizes the details in each of the exposuresthat that particular exposure captures well. The overexposed image showsgood detail in the dark areas; therefore the composite is weightedtoward using pixels from the overexposed image to generate pixels in thedark areas of the image. The underexposed image shows good detail in thebright areas; therefore the composite is weighted toward using pixelsfrom the underexposed image to generate pixels in the bright areas ofthe image. The normally exposed image shows good detail in the midtoneareas; therefore the composite is weighted toward using pixels from thenormally exposed image for the midtone areas of the image.

After aligning the images, as described in section IV, the imageprocessing module of some embodiments performs the compositing of thethree aligned images to produce a composite HDR image. In differentembodiments, the image processing module uses different techniques tocomposite the three images. Some embodiments composite the three imagesby performing separate sets of operations for a luma channel of theseimages than for the chroma channels of these images. In someembodiments, the separate operations on the chroma channel images arethe same as or similar to the operations on the luma images. Also, ingenerating the HDR composite image, some embodiments might produce lumaand chroma values that exceed a desired range of values. Accordingly,while generating the HDR image, some embodiments concurrently performscaling operations to ensure that the luma and chroma values of the HDRimage are generated within their desired ranges. In some embodiments,the generation of a final HDR image is conceptually divided into HDRcapturing operations and HDR rendering operations. In the HDR capturingoperations, an initial HDR image is generated from multiple images takenwith different exposure times. In the HDR rendering operations of someembodiments, the initial HDR image is adjusted by one or more operationsincluding boosting the image's shadows, attenuating the image'shighlights, histogram stretching of the image, and chroma saturation ofthe chroma components of the image.

To identify which areas of each image should be used to generate thecorresponding areas of a composite luma image, some embodiments generatethree masks. The three masks correspond to the three exposure levels. Toidentify the areas of each exposure to use in the composite, each maskprovides a weighting factor at each point of its corresponding exposure.In some embodiments, the normally exposed image is used to identifybright, dark, and midtone areas of the image in order to generate thethree masks. A composite image is then generated, pixel by pixel, usingthe masks as a weighting factor for each pixel. A high value in aparticular mask for a particular pixel means that the pixel in theexposure corresponding to that mask will strongly influence thecorresponding pixel in the composite image. A low value in a particularmask for a particular pixel means that the pixel in the exposurecorresponding to that mask will weakly influence the corresponding pixelin the composite image. At the extreme ends of the scale, a value of onefor a particular pixel in a mask of a particular exposure means that thevalue of the corresponding pixel in the composite will entirely dependon the value of the corresponding pixel in that exposure. Similarly, avalue of zero for a particular pixel in a mask of a particular exposuremeans that the value of the corresponding pixel in the composite willnot depend at all on the value of the corresponding pixel in thatexposure.

While the masks weight the individual pixels, some embodiments alsoweight all pixels in each image by a factor that compensates for therelative exposure times of each exposure. In some embodiments, theexposure times used in these calculations are provided by the camera ofthe mobile device.

In some embodiments, to make the colors scale properly with the lumavalues, the chroma values of the images are also composited with asimilar weighting scheme as the luma values. That is, the chromachannels (Cb and Cr) of the exposures are composited with the same masksand scaling as the luma channels of the exposures. The colors of themidtones of the image are enhanced in some embodiments, either duringthe compositing or after the compositing.

B. Compositing Luma or Luminance

The mobile devices of some embodiments generate HDR images bycompositing multiple images taken at different exposures. Compositingthe images in some embodiments, generates an image in which the value ofeach pixel is a weighted average of the values of corresponding pixelsin each of the three images. In some embodiments, the composite is aweighted average of luma components of the images. In other embodiments,the composite is a weighted average of luminance components of theimages. That is, various embodiments composite images in variousdifferent image formats. Some embodiments perform all operations onimages in a luma (Y′) format. In other embodiments, all operations areperformed on images in a luminance (Y) format. In still otherembodiments, the mobile devices start with images in a luma (Y′) formatand convert the luma (Y′) components to luminance (Y) components, thenperform operations on the luminance (Y) components. After luminanceimages are composited, the mobile devices of some embodiments convertthe resulting composite images from luminance (Y) to luma (Y′). Thefollowing description identifies some places in the compositing processwhere such conversions can take place; however, one of ordinary skill inthe art will understand that in other embodiments, the conversions cantake place during other parts of the process.

FIG. 12 illustrates a process 1200 for compositing the luma channelimages of three different exposures of the same scene and adjustingvarious luma values of the resulting composite image. Process 1200 isperformed each time the compositing module 120 receives three (in someembodiments cropped) images from the alignment module 115. This processwill be described by reference to FIG. 13A, which illustrates an exampleof performing the process 1200 on a particular scene. The process 1200is explained with references to items in FIG. 13A, however one ofordinary skill in the art will understand that this is for ease ofexplanation and that the calculations are not limited to the particularscene in that figure.

The scene in FIG. 13A is a car sitting on a mountain road. The sceneincludes a bright sky and backlit mountains that are dark as well as acar and road that are midtoned. FIG. 13A includes three images (e.g.,color images) taken at different exposures 1310A-1310C, the luma channelimages (sometimes referred to as luma images) 1320A-1320C of each of theimages, masks 1330A-1330C, composite luma image 1340, Gaussian blurredcomposite 1350, highlight-attenuated image 1360A and shadow-enhancedimage 1360B, composite image 1370 and final luma image 1380. The threeimages taken at different exposures 1310A-1310C represent the colorimages taken at different exposure levels. Image 1310A is theunderexposed image, 1310B is the normally exposed image, and 1310C isthe overexposed image. In some embodiments, image 1310A is exposed for ¼as long as image 1310B, and image 1310C is exposed for 4 times as longas image 1310B. The exposure time ratios may be numbers other than 4 inthe same embodiment or in other embodiments. The luma channel images1320A-1320C represent only the luma information of the color images1310A-1310C. In some embodiments, the luma channel data is providedseparately from the chroma channel data, while in other embodiments, theluma channel data is extracted from the color images.

As described in relation to FIG. 1, the mobile device of someembodiments generates the three images (e.g., images 1310A-1310C) usingdifferent exposure times for each image. In some embodiments, theseexposure times are measured in terms of the exposure value compensation(EV). For a given aperture of a camera on a mobile device, the amount ofexposure time is proportional to 2 to the power of the EV. For example,an EV of 3 increases the exposure time by a factor of 8. In someembodiments, relative to the normally exposed image, the overexposedimage is shot with an EV of +2 and the underexposed image is shot withan EV of −2. In such embodiments, the overexposed image is exposed for 4times as long as the normally exposed image and the underexposed imageis exposed for ¼ as long as the normally exposed image. Variousembodiments use different EV values than plus or minus 2. Someembodiments adjust EVs for different lighting conditions. For example,some embodiments determine which exposure values to use based on ahistogram of the normally exposed image (e.g., a histogram generatedfrom a normally exposed preview image). Some such embodiments maintain aconstant difference between EV+ value and the EV− value. In someembodiments, the EV of the overexposure can be a different magnitudefrom the EV of the underexposure in some lighting conditions. Forexample, some embodiments use EV −3 and EV +1 for the underexposed andoverexposed images respectively in very bright scenes. Some embodimentsuse EV −1 and EV +3 for the underexposed and overexposed imagesrespectively in very dark scenes.

The compositing process 1200 of FIG. 12 initially performs the HDRcapture operations, beginning with three luma images taken withdifferent exposure times (e.g., luma images 1320A-1320C). The processgenerates (at 1210) three masks, corresponding to the three luma images1320A-1320C, from the normally exposed luma image 1320B. The normallyexposed luma image 1320B is used to identify which parts of the scenebeing photographed are bright, which parts are midtoned, and which partsof the scene are dark. In FIG. 13A, the bright areas of the normallyexposed luma image 1320B include the sky and the wheels of the car, thedark areas include the mountains, and the midtone areas include the bodyof the car and the road. The masks are a set of weights for compositingthe pixels. In some embodiments, each mask has the same resolution asthe images to be composited. The masks can be represented as an image,and it is convenient to describe the values in a mask as pixel values,however the data in the masks is intended for use in compositingcalculations, not primarily for visual display.

The three masks correspond to the three luma images 1320A-1320C. Theunderexposed luma image 1320A provides the best detail in bright areas.Therefore, the mask 1330A for the underexposed luma image 1320A has highvalues for pixels that correspond to bright pixels in the normallyexposed luma image 1320B and low values for pixels that correspond tomedium and dark pixels in the normally exposed luma image 1320B. Theoverexposed luma image 1320C provides the best detail in dark areas.Therefore, mask 1330C for the overexposed luma image 1320C has highvalues for pixels that correspond to dark pixels in the normally exposedluma image 1320B and low values for pixels that correspond to medium andbright pixels in the normally exposed luma image 1320B. The normallyexposed luma image 1320B provides the best detail in midtone areas.Therefore, mask 1330B for the normally exposed luma image 1320B has highvalues for pixels that correspond to midtone pixels in the normallyexposed luma image 1320B and low values for pixels that correspond tobright and dark pixels in the normally exposed luma image 1320B.

Some embodiments provide masks with a range of values to blend thepixels from different luma images 1320A-1320C, rather than usingseparate pixels from each image. The higher the value of a pixel in amask, the more influence the corresponding pixel in the correspondingimage has on the value of the corresponding pixel in the compositeimage. For ease of identification of the areas of each image, the masks1330A-1330C only have black areas and white areas in FIG. 13A, however avisual representation of the masks of some embodiments would includegrey pixels. Such grey pixels would represent pixels that influence, butdo not completely determine, the value of the corresponding pixel in thecomposite image.

The following equations (1)-(3) are used in some embodiments to generatethe masks. These equations result in three curves based on hyperbolictangents that provide three sets of weighting values that provide aninitial bias to composite the HDR image by taking details of dark areasfrom the overexposed image, taking details of bright areas from theunderexposed image, and taking details of midtones from the normallyexposed image, as mentioned above. Instead of using equations/curvesbased on hyperbolic tangents, other embodiments use other types ofsigmoidal or other non-linear functions/curves to specify the maskingvalues used for selectively weighting the images to produce a compositeimage.

The equations herein follow a convention that each variable isrepresented by a single capital letter, in some cases the capital letteris followed by a single lower case letter, especially when variablesthat serve the same function for different masks or images are beingused. Variables that have different values for different individualpixels in the images are denoted by a [x,y] following the initialletters to indicate that their value in the equation is determined on aper pixel basis with the x and y representing the coordinates of thepixel in the image. The variables with different values for differentpixels are calculated for each pixel over the entire range of pixels inthe image. The equations are explained with references to items in FIG.13A, however one of ordinary skill in the art will understand that thisis for ease of explanation and that the calculations are not limited tothe particular scene in that figure.

In some embodiments, the values of the pixels in the masks 1330A-1330Care generated using the following equations:Mb[x,y]=0.5*(tan h(−Sb*(Ln[x,y]−Tb))+1)  (1)Mu[x,y]=0.5*(tan h(Su*(Ln[x,y]−Tu))+1)  (2)Mn[x,y]=1−Mb[x,y]−Mu[x,y]  (3)

In equation (1), Mb[x,y] represents the value of the overexposure mask1330C at coordinates [x,y] and is a function of the luma value Ln[x,y]of the corresponding pixel of the normally exposed luma image 1320B. Tbis a threshold luma value for the overexposed image. Sb affects theslope of the function. In any equation in which it appears herein, tan his the hyperbolic tangent. Instead of performing a tan h calculation inreal-time, some embodiments use a look-up table to identify valuesproduced by tan h for a given input. Some embodiments use look-up tablesin place of other calculations instead of, or as well as, tan h.

In equation (2), Mu[x,y] represents the value of the underexposure mask1330A at coordinates [x,y]. Like Mb[x,y], it is also a function of theluma value Ln[x,y] of the corresponding pixel of the normally exposedluma image 1320B. Tu is a threshold luma value for the underexposedimage. Su affects the slope of the function. In equation (3), Mn[x,y]represents the value of the normal exposure mask 1330B at coordinates[x,y].

The purpose of the overexposure mask 1330C, is to increase the influenceof the pixels in dim areas (where the overexposed luma image 1320Cprovides good detail) and increase the influence of the pixels in brightareas (where the overexposed luma image 1320C is most likely saturated).Accordingly, in equation (1), the weighting of a pixel from overexposedluma image 1320C is a smooth, decreasing function of the luma value ofthe corresponding pixel in the normally exposed luma image 1320B. Sb hasa negative sign in front of it, indicating that positive values of Sb,as used in some embodiments, will result in a function that decreaseswith luma value. For a positive value of Sb, the brighter a pixel in thenormally exposed luma image 1320B is, the less weight is given to thecorresponding pixel in the overexposed image when generating thecomposite image.

As mentioned above, Tb is a threshold luma value for the overexposedimage. When a pixel in the normally exposed luma image 1320B has a valuebelow Tb (darker than threshold), the corresponding pixel ofoverexposure mask 1330C has a value of more than ½. When a pixel in thenormally exposed luma image 1320B has a value of Tb (at threshold), thecorresponding pixel of overexposure mask 1330C has a value of ½. When apixel in the normally exposed luma image 1320B has a value above Tb(brighter than threshold), the corresponding pixel of overexposure mask1330C has a value of less than ½. In some embodiments, the value of Tbis determined by dividing 0.015 by the median value of the luma of thepixels in the normally exposed luma image 1320B. For example, if themedian value for the lumas of the pixels in normally exposed luma image1320B is 0.1, then the value of Tb would be 0.15. In some embodiments,the value of Tb is determined by dividing 0.02 (or some other value) bythe median value of the luma of the pixels in the normally exposed lumaimage 1320B. Some embodiments have different ways of calculating Tbdepending on characteristics of the images. For example, someembodiments calculate Tb based on the average (mean) luma of a lumaimage (e.g., 1320B) rather than from the median luma.

Sb determines how quickly the function Mb[x,y] changes around thethreshold value Tb. A very high value for Sb, results in a rapid change.For a high value of Sb, pixels in the normally exposed luma image 1320Bwith a luma value just above the threshold Tb will result in thecorresponding pixel in the mask 1330C having a very low value. The lowvalue of the pixel in the mask means that the corresponding pixel in theoverexposed luma image 1320C will have almost no influence on the valueof the corresponding pixel of the composite image 1340. Pixels in thenormally exposed luma image 1320B with a luma value just below thethreshold will result in the corresponding pixel in the mask 1330Chaving a very high value (with a maximum of 1). The value of thecorresponding pixel in the overexposed luma image 1320C will almostentirely determine the value of the corresponding pixel of the compositeimage 1340. In contrast, a low value of Sb will result in a gradualshift in influence when crossing the threshold. For a low value of Sb,pixels in the normally exposed luma image 1320B with a luma value justbelow the threshold will result in the corresponding pixel in the mask1330C having slightly more than 50% influence on the corresponding pixelof the composite image 1340. For a low value of Sb, pixels in thenormally exposed luma image 1320B with a luma value just above thethreshold will result in the corresponding pixel in the mask 1330Chaving slightly less than 50% influence on the corresponding pixel ofthe composite image 1340. In some embodiments, the value of Sb is 10.

The purpose of the underexposure mask 1330A, is to increase theinfluence of the pixels in bright areas (where the underexposed lumaimage 1320A provides good detail) and decrease the influence of thepixels in dim areas (where the underexposed luma image 1320A is mostlikely too dark to show details). Accordingly, in equation (2) thevalues of the pixels in the underexposure mask 1330A should be anincreasing function of the luma value of the corresponding pixel in thenormally exposed luma image 1320B. The slope determiner Su does not havea minus in front of it, therefore positive values of Su result in apositive function of luma. The threshold Tu in equation (2) is differentfrom the threshold Tb in equation (1). In some embodiments, the value ofTu is determined by multiplying the median luma value of the normallyexposed luma image 1320B by 6 (or some other value). In someembodiments, when the product of the median luma value and the factor(e.g. 6) is greater than 1, the value of Tu is set to 1. Someembodiments have different ways of calculating Tu depending oncharacteristics of the images. Similar to the case for Sb, the magnitudeof Su determines how fast the influence (on the composite image 1340) ofthe pixels of the underexposed luma image 1320A changes as a function ofthe luma value of the corresponding pixel in the normally exposed lumaimage 1320B. A high value for Su provides for a rapid change from noinfluence to large influence as the luma value of the pixels of normallyexposed luma image 1320B go from below the threshold Tu to above thethreshold. A low value for Su provides for a gradual change from noinfluence to large influence as the luma value of the pixels of normallyexposed luma image 1320B go from below the threshold Tu to above thethreshold.

The pixels of the normal exposure mask 1330B have a value of 1 minus thevalues of the corresponding pixels in the other masks 1330A and 1330C.The normal exposure mask 1330B has higher values where both the othermasks have lower values and lower values where either of the other masks(or their aggregate) have higher values. For example, assuming that Suvalue is equal to the Sb value used to generate the other masks, thecombined values of the other two masks is lowest for pixels at theaverage value of Tb and Tu. Therefore, normal exposure mask 1330B hasits highest value for pixels in corresponding to pixels in normallyexposed luma image 1320B with luma values at the average value of Tb andTu.

A visual representation of a mask that has a gradual transition (e.g.,with a low magnitude of Su or Sb) from one mask dominating the value ofa pixel to another mask dominating the value of the pixel would containgrey areas corresponding to areas of the composite that were influencedpartly by one mask and partly by another mask. In contrast, a visualrepresentation of a mask that has abrupt transitions (e.g., with a highmagnitude of Su or Sb) from one mask to another would be almost entirelyblack pixels and white pixels, with few grey pixels (if any). The masks1330A-1330C were generated using very high values of Su and Sb,therefore they have no grey pixels. A pixel in the normally exposed lumaimage 1320B that is any dimmer than the threshold Tb results in a whitepixel in the overexposure mask 1330C. A pixel in the normally exposedluma image 1320B that is any brighter than the threshold Tb results in ablack pixel in the overexposure mask 1330C. A pixel in the normallyexposed luma image 1320B that is any dimmer than the threshold Turesults in a black pixel in the underexposure mask 1330A. A pixel in thenormally exposed luma image 1320B that is any brighter than thethreshold Tu results in a white pixel in the overexposure mask 1330A. Apixel in the normally exposed luma image 1320B that is between thethresholds Tu and Tb results in a white pixel in the normal exposuremask 1330B. A pixel in the normally exposed luma image 1320B that is notbetween thresholds Tu and Tb results in a black pixel in the normalexposure mask 1330B. In sum, the underexposure mask 1330A provides theentire weight (in the composite) of the bright pixels, the normalexposure mask 1330B provides the entire weight of the midrange pixels,and the overexposure mask provides the entire weight of the dark pixels.The extreme cutoffs in masks 1330A-1330C are provided because they makeit easy to identify the various areas of high and low weight in a blackand white figure. However, in embodiments with lower values of Sb andSu, the corresponding masks would include a range of values. In visualterms, the masks would include grey areas that represent sharedinfluence over the luma of the pixel in the composite.

To generate an overexposed image mask, some embodiments adjust thethreshold luma value Tb from the value described above. Some embodimentsadjust the threshold luma value Tb because the signal-to-noise ratio ofthe overexposed image decreases with increasing exposure time (e.g.,longer exposure times cause more noise in the image). Accordingly, toreduce the noise in the composite image, some embodiments adjust thethreshold luma value Tb to include less of the overexposed image in thefinal composite. In some embodiments, the following equation is used toadjust the thresholdTb=Tb*0.5*(tan h(4*(Fb−Ft))+1)  (4)

In equation (4), the first Tb is the threshold luma value afteradjustment; the second Tb is the threshold luma value before adjustment.Fb is the signal-to-noise ratio in decibels (dB) of the overexposedimage. Ft is a threshold signal-to-noise ratio. Signal-to-noise ratiosabove the Ft threshold increase the threshold luma of the overexposedimage, which increases the number of pixels in the overexposed imagethat have a high influence on the composite image 1340. In someembodiments, Ft is 24 dB. During calibration of the mobile device (or aprototype of the mobile device) in some embodiments, the signal-to-noiseratio is measured for a series of light levels (e.g., 5 light levels).These measured signal-to-noise ratios are used to determine thesignal-to-noise ratio for a given image. In some embodiments, thecalibration is performed on each mobile device. In other embodiments,the calibration is performed on a sample (one or more) of the mobiledevices to determine the calibration points for that type of mobiledevice, these calibration points are then used for other mobile devicesof the same type. Some embodiments have default calibration points butallow new calibration points to be calculated for a particular mobiledevice. The light level of a particular image is determined by themobile device when the image is captured. In embodiments with acalibrated mobile device, based on the light level, the signal-to-noiseratio of the image is interpolated from the signal-to-noise ratio of thecalibration points.

In some embodiments, masking based on individual pixels can result in aloss of contrast. More detail will be preserved when pixels that don'tmatch the nearby pixels (bright pixels in otherwise dark areas, etc.)are more heavily influenced by the images that provide the best detailfor that area, rather than the image that provides the best detail forthat pixel value. For example, in such embodiments, the composite valuefor a dark pixel in a bright background would be most influenced by thecorresponding pixel of the underexposed image that is better forproviding details for bright pixels (like the background) rather than bythe overexposed image, which is better for providing details for darkpixels. Furthermore, compositing without blurring the mask can result inhigh frequency transitions in the composite between pixels derived fromdifferent exposures because the weights are not spatially smooth.Therefore, some embodiments blur the masks to reduce high frequencytransitions in the composite by making the weights spatially smooth, inaddition to or instead of blurring the masks to improve contrast at theboundaries between light and dark areas. Therefore, in some embodiments,process 1200 adjusts (at 1215) the masks to improve contrast at theboundaries between light and dark areas and/or to reduce high frequencytransitions in the composite. Accordingly, the masks of some embodimentsare blurred before being applied as weights for the composite image1340. In some such embodiments, the masks are blurred using a equationsuch as:Mb[x,y]=filter(Mb[x,y],k)  (5)Mu[x,y]=filter(Mu[x,y],k)  (6)

In equation (5), the first Mb[x,y] represents the mask after theblurring filter is applied; the second Mb[x,y] represents the maskbefore the blurring filter is applied. The filter in equations (5) and(6) is a 2D filter operation using filter k. Item k is a 2D Gaussianfilter kernel. In some embodiments, a 7×7 or a 9×9 filter kernel is usedwith a pixel variance of 3. In equation (6), the first Mu[x,y]represents the mask after the blurring filter is applied; the secondMu[x,y] represents the mask before the blurring filter is applied.

The size of the filter kernel (k) can affect the results of the blurringoperation. Large values of k can result in large halo effects, but smallvalues of k can result in a loss of contrast within an area. Theblurring ensures that the masks will provide weights based on thebrightness of the area a pixel is in, rather than providing weightsbased on the brightness of the individual pixel. In some embodiments,this improves contrast within areas that have pixels from multipleranges (dark, midtone, and/or bright). Equations (5) and (6) areperformed before equation (3), in some embodiments, so that the normalexposure mask 1330B is generated from the blurred masks generated byequations (5) and (6) rather than by the masks generated by equations(1) and (2).

The above description of mask generation describes the generation ofmasks using data from a normally exposed luma image 1320B, but not theother luma images 1320A and 1320C. However, using the normally exposedluma image 1320B to generate all three masks 1330A-1330C can lead tosituations where over-blown (e.g., saturated) areas of the overexposedimage are used. It can also lead to situations where areas of theunderexposed image that are too dark are used. Therefore, in someembodiments, masks generated from luma images are generated using lumavalues from the overexposed and underexposed images instead of or inaddition to luma values from the normal image. FIG. 13B illustrates anexample of performing the process 1200 and generating masks 1330A-1330Cfrom each image. In FIG. 13B, the underexposure mask 1330A is generatedfrom the underexposed luma image 1320A, the overexposure mask 1330C isgenerated from the overexposed luma image 1320C and the normal exposuremask 1330B is generated from the overexposed luma image 1320C andunderexposed luma image 1320A. Though FIG. 13B shows the normal exposuremask as being generated using the underexposed luma image 1320A and theoverexposed luma image 1320C, in some embodiments, the normal exposuremask 1330B is generated from the underexposure mask 1320A and theoverexposure mask 1320C using equation (3). In some embodiments, thenormal exposure mask 1330B is generated from the underexposure mask1320A and the overexposure mask 1320C after the underexposure mask 1320Aand the overexposure mask 1320C are blurred.

In some embodiments that generate masks from the underexposed andoverexposed images, the masks are generated using similar equations toequations (1)-(6), but with the luma values (Lb[x,y]) from theoverexposed images substituting for the Ln[x,y] for the overexposuremask, the luma values (Lu[x,y]) from the underexposed image substitutingfor the Ln[x,y] for the underexposure mask, and the thresholds adjustedaccordingly. In some such embodiments, the threshold values forcalculating the overexposure and underexposure masks are derived fromthe median luma values of the respective images. In other embodiments,the threshold values are derived from the median luma value of thenormally exposed image (e.g., in the same way as in the above describedembodiments that generate masks from the normally exposed image). Inother embodiments, the threshold values are set to default values of 0.4for Tb (for the overexposure mask) and 0.5 for Tu (for the underexposuremask). In still other embodiments, the threshold values are set todefault values of 0.5 for Tb (for the overexposure mask) and 0.5 for Tu(for the underexposure mask).

After the process 1200 has generated (at 1210) the masks (e.g., masks1330A-1330C). The process then generates (at 1220) a composite lumaimage (e.g., luma image 1340), which includes details taken from eachindividual luma exposure (e.g., 1320A-1320C). In composite luma image1340 the details from the car body and road of normally exposed lumaimage 1320B, the details from the mountains of the overexposed lumaimage 1320C, and the details from the sky and wheels of underexposedluma image 1320A are all present. In some embodiments, the luma images1330A-1330C are composited using the following equation:

$\begin{matrix}{{{Lc}\lbrack {x,y} \rbrack} = {{{Eb}*{{Lb}\lbrack {x,y} \rbrack}*{{Mb}\lbrack {x,y} \rbrack}} + {{En}*{{Ln}\lbrack {x,y} \rbrack}*{{Mn}\lbrack {x,y} \rbrack}} + {{Eu}*{{Lu}\lbrack {x,y} \rbrack}*{{Mu}\lbrack {x,y} \rbrack}}}} & ( {7A} )\end{matrix}$

In equation (7A), Lc[x,y] is the luma value of the pixel at coordinates[x,y] in the composite image 1340. Lb[x,y] is the luma value of thepixel at coordinates [x,y] in the overexposed (bright) luma image 1320C.Ln[x,y] and Lu[x,y] are the luma values for the normally exposed lumaimage 1320B and underexposed luma image 1320A, respectively. Eb is anexposure scaling factor for the exposure of the overexposed luma image1320C. En and Eu are the corresponding scaling factors for the normallyexposed luma image 1320B and underexposed luma image 1320A,respectively. Mb[x,y] represents the value of the overexposure mask1330C at coordinates [x,y]. Mn[x,y] and Mu[x,y] represent the values forthe normal exposure mask 1330B and underexposure mask 1330A,respectively. The value of a pixel in the mask 1330C determines how mucheffect the corresponding pixel in the overexposed luma image 1320C hason the composite image. The value of a pixel in the mask 1330Bdetermines how much effect the corresponding pixel in the normallyexposed luma image 1320B has on the composite image. The value of apixel in the mask 1330A determines how much effect the correspondingpixel in the underexposed luma image 1320A has on the composite image.In each mask 1330A-1330C higher values mean more influence on thecomposite image.

The exposure scaling factors (Eu, En, and Eb) compensate for thedifferent exposure times of the images (e.g., if the overexposed imagehas 4 times the exposure time than the normally exposed image thenEb=En/4). The more exposed images have higher luma values because theyare exposed longer, not because their data is “better”, or because theyrepresent brighter parts of the image. Without compensating for thelonger exposure time, the data from the overexposed image would dominatethe results more than their informational value would indicate. In someembodiments, the ratio of the exposure times is something other than 4.The ratios of underexposed-duration to normal-exposure-duration aredifferent than the ratios of normal-exposure-duration tooverexposed-duration in some embodiments. In such embodiments, theexposure scaling factors would be adjusted to reflect the differentratios of exposure times.

In embodiments that use formats in which the values of the pixels are alinear function of the light that reaches the corresponding sensors, theexposure scaling factors compensate uniformly for the differences inpixel values caused by different exposure times. When the values of thepixels are a linear function of the light that reaches the sensors,then, in the absence of other factors (e.g., varying brightness of thepart of the scene captured by a particular sensor), the value of a pixelwould be four times greater in an overexposed image with four times thenormal exposure time than the value of the corresponding pixel in anormally exposed image of the same scene. In such a format, the pixelsin each exposure of the same scene have the same values relative to eachother. That is, if one pixel in the normal exposed image is twice thevalue of another pixel in the normal exposed image, then the pixel ofthe overexposed image that corresponds to the first pixel in the normalimage will have twice the value of the pixel in the overexposed imagethat corresponds to the second pixel in the normal image.

Some mobile devices capture images in a format that includes a component(e.g., luminance) that is a linear function of the amount of light thatreaches the sensors (up to a saturation point). However, some suchdevices automatically convert the luminance images into luma imagesusing a non-linear transformation (e.g., gamma correction). Because ofthe non-linear transformation from luminance to luma, luma values arenot a linear function of exposure time. The luma values are not a linearfunction because gamma correction changes the values near the bottom ofthe luminance range more than values near the middle and high ends ofthe luminance range. Overexposed images, which are taken with longexposure times, are brighter than normally exposed images and haveluminance values that cluster near the top of the luminance range of thecamera. Underexposed images, which are taken with short exposure timesare darker than average and have luminance values that cluster near thebottom of the luminance range of the camera. The images taken withnormal exposures have luminance values that cluster near the middle ofthe luminance range of the camera. Because of the different levels ofbrightness of the different exposures, gamma correction can change therelative brightness of corresponding objects in the different exposuresdifferently. Changing the relative brightness of objects in thedifferent exposures affects the results of compositing the images.

Accordingly, to return the images to a format in which the values are alinear function of exposure time, some embodiments reverse the gammacorrection of the luma (Y′) components of the images to generateluminance (Y) images. Some such embodiments perform operations on theluminance images, then apply a new gamma correction after the operationsto produce a final image with a luma (Y′) component. The inverse gammacorrection is performed during compositing in some embodiments. Somesuch embodiments generate the composite image using the followingequation (7B) rather than using equation (7A)

$\begin{matrix}{{{Lc}\lbrack {x,y} \rbrack} = {{{Eb}*{{{Lb}\lbrack {x,y} \rbrack}\hat{}( {1/\gamma} )}*{{Mb}\lbrack {x,y} \rbrack}} + {{En}*{{{Ln}\lbrack {x,y} \rbrack}\hat{}( {1/\gamma} )}*{{Mn}\lbrack {x,y} \rbrack}} + {{Eu}*{{{Lu}\lbrack {x,y} \rbrack}\hat{}( {1/\gamma} )}*{{Mu}\lbrack {x,y} \rbrack}}}} & ( {7B} )\end{matrix}$

Equation (7B) is almost the same as equation (7A), except that the lumavalues Lb[x,y], Ln[x,y], and Lu[x,y] have been raised to the power of(1/γ). And the Lc[x,y] values are luminance values rather than lumavalues. In some embodiments, the mobile device provides luma values thatare based on luminance values of a captured image raised to the power ofgamma (γ) (in some embodiments, gamma is equal to 1/2.2). The mobiledevices of some embodiments provide the value of gamma as metadata ofthe provided images. In some such embodiments, the provided gamma isused in the equation (7B) to recreate the original luminance valueswhile the images are being composited. Other such embodiments performthe inverse gamma correction before compositing the images and useequation (7A) on luminance values generated in a separate operation fromthe compositing operation.

Similarly, while the above equations are described in terms of masksgenerated from luma images, one of ordinary skill in the art willunderstand that the masks of some embodiments are generated from imagesin other formats. For example, in some embodiments the masks aregenerated from luminance versions of one or more of the images, ratherthan luma versions. In some embodiments, the type of image used togenerate the masks (e.g., luma or luminance) is the same as the type ofimage used to generate the composite. In other embodiments, the type ofimage used to generate the masks (e.g., luma or luminance) is differentfrom the type of image used to generate the composite.

To generate the composite image using equations (7A) or (7B), thescaling factor of the overexposed image (Eb) is adjusted from the actualratio of exposure times in some embodiments. Some embodiments use thefollowing equation to adjust the scaling factor of the overexposed imageEb to boost the shadows.Eb=En/(Er+(⅔*(Ts−0.25)*(1−Er)*(1−tan h(12N−3.5))))  (8)

In equation (8), Eb is the scaling factor for the overexposed image; Enis the scaling factor for the normally exposed image. Er is the ratio ofthe exposure time of the normally exposed image to the exposure time ofthe overexposed image (e.g., ¼ if the overexposed image has 4 times aslong an exposure as the normally exposed image), Ts is a thresholdfactor. In some embodiments, Ts is set to 0.4. N is the median luma (ona luma scale from 0 to 1). The median luminance is used for N instead ofthe median luma in some embodiments.

In some embodiments, once equation (7A) or (7B) has been performed, thecalculated composite image is mapped back (e.g., rescaled) to aparticular range (e.g., 0-1, or 0-255) by a normalization:Lc[x,y]=Ec*Lc[x,y]/max(Lc)  (9A)

In equation (9A), the first Lc[x,y] is the luma of the pixel atcoordinates [x,y] in the composite image 1340 after the normalization,the second Lc[x,y] is the luma of the pixel at coordinates [x,y] in thecomposite image before the normalization, max(Lc) is the maximum lumavalue of any pixel in the composite image before the normalization andEc is a scaling factor specifying the range. Some embodiments normalizeby the highest possible pixel value, which is 1*Eu. This is done toavoid changing the over brightness of the HDR image compared to EV0.

Some embodiments apply a different normalization factor rather thanmax(Lc). Equation (9B) provides an alternate equation for normalizingthe composite image.Lc[x,y]=Ec*Lc[x,y]/Eu  (9B)

In equation (9A), the first Lc[x,y] is the luma of the pixel atcoordinates [x,y] in the composite image 1340 after the normalization,the second Lc[x,y] is the luma of the pixel at coordinates [x,y] in thecomposite image before the normalization, En/Eb is an exposure scalingfactor for the exposure of the overexposed image (e.g., if theoverexposed image has four times the exposure time of the normalexposure, then En/Eb=4) and Ec is a scaling factor specifying the range.In some embodiments, Ec is set to 1, in other embodiments Ec is set to1.2, in other embodiments Ec is set to other values.

In some embodiments, the capturing operations end after the rescaling ofequation (9A) or (9B). In such embodiments, the rendering operationsthen begin when process 1200 generates (at 1230) a Gaussian blurredcomposite 1350 version of the composite luma image 1340. The Gaussianblurred composite 1350 is created for a reason similar to the reason forcreating the Gaussian blurs of the individual masks. The Gaussianblurred composite 1350 is used as a weight for adjusting other images inother parts of the process 1200 and the blurring enhances the effects(on the final images) of pixels that have very different values from thepixels around them. The Gaussian blur is generated by a similar processto the mask blurring of equations (5) and (6).G[x,y]=filter(Lc[x,y],k)  (10)

In equation (10), the G[x,y] represents the Gaussian blurred composite1350. Lc[x,y] represents the luma of a pixel at (x, y) of the compositeimage 1340. The filter is a 2D filter operation using filter k. Item kis a 2D Gaussian filter. In some embodiments, a 7×7 or a 9×9 filter isused with a pixel variance of 3. The same filter and kernel are used insome embodiments for blurring the masks in equations (5) and (6) andblurring the Gaussian blurred image in equation (10), in otherembodiments, different filters and/or kernels are used.

As with the masks, large values of k can result in large halo effects,but small values of k can result in a loss of contrast within an area.The blurring ensures that the Gaussian blurred composite 1350 willweight based on the brightness of the area a pixel is in, rather thanweighting based on the brightness of the individual pixel. In someembodiments, weighting based on the area improves contrast within areasthat have pixels from multiple ranges (dark, medium, and/or bright).

Once the Gaussian blurred composite 1350 is generated, the process 1200generates (at 1240) a highlight-attenuated image 1360A and ashadow-boosted image 1360B. The shadow-boosted image 1360B includes anexpanded range of light levels in the dark areas of the image and acompressed range of light levels in the bright areas. In other words, indark areas, the difference between luma values is expanded in theshadow-boosted image. For example, a pixel in the composite image 1340with a luma of 0.02 might be converted into a pixel in theshadow-boosted image of 0.14 and a pixel in the composite image 1340with a luma of 0.03 might be converted into a pixel in theshadow-boosted image of 0.19. In each case, the magnitude of the lumavalues of the pixels increase, but more significantly, the difference inmagnitude of the luma values increases. For pixels in the brighterareas, the magnitude of the luma values for the pixels also increases,but the difference between the magnitudes of the luma values of twopixels decreases. In other words, the shadow boost increases brightnessvalues throughout the range, but in the lower end of the range, theincrease between neighboring values is more than in the higher end ofthe range (i.e., the increase in brightness of dark regions is more thanthe increase of the brightness of bright regions).

Similarly, the highlight-attenuated image 1360A expands the range oflumas for the brighter pixels and contracts the range of lumas for thedarker pixels of composite image 1340. In other words, the highlightattenuation decreases brightness values throughout the range, but in thehigh end of the range, the decrease between neighboring values is morethan in the lower end of the range (i.e., the decrease in brightness ofbright regions is more than the decrease of the brightness of darkregions).

In some embodiments, the shadow-boosted image 1360B is generated by thefollowing equation:Ls[x,y]=Lc[x,y]/(Bs*G[x,y]+(1−Bs))  (11)

In equation (11), Ls[x,y] is the luma value of the pixel at coordinates[x,y] in the shadow-boosted image 1360B. G[x,y] is the value of thepixel at coordinates [x,y] in the Gaussian blurred composite 1350. Bs isa scaling factor. Bs is equal to 0.83 in some embodiments. In otherembodiments, other values are used.

The highlight-attenuated image 1360A is generated by the followingequation in some embodiments:Lh[x,y]=1−((1−Lc[x,y])/((1−Bh)*(1−G[x,y])+Bh))  (12)

In equation (12), Lh[x,y] is the luma value of the pixel at coordinates[x,y] in the highlight-attenuated image 1360A. G[x,y] is the value ofthe pixel at coordinates [x,y] in the Gaussian blurred composite 1350.Bs is a scaling factor. In some embodiments, Bs is equal to 0.7. Inother embodiments, other values are used for the scaling factor.

The process 1200 composites (at 1250) the shadow-boosted image 1360B andthe highlight-attenuated image 1360A to create a composite image 1370.The composite image 1370 of some embodiments is generated using thefollowing equation:Lc[x,y]=(Ls[x,y]*(1−G[x,y]))+(Lh[x,y]*G[x,y])  (13)

In equation (13), Lc[x,y] is the luma value of the pixel at coordinates[x,y] in the composite image 1370. Lh[x,y] is the luma value of thepixel at coordinates [x,y] in the highlight-attenuated image 1360A.G[x,y] is the value of the pixel at coordinates [x,y] in the Gaussianblurred composite 1350. Ls[x,y] is the luma value of the pixel atcoordinates [x,y] in the shadow-boosted image 1360B. The combination ofthe shadow-boosted image 1360B and the highlight-attenuated image 1360A,as weighted in equation (13) has the net effect of emphasizing detailsin both the bright and the dark areas of the image. In some embodiments,as part of compositing the shadow-boosted image 1360B and thehighlight-attenuated image 1360A, any pixels that have a luma greaterthan the top of the allowed range are reduced to the top of the allowedrange (e.g., a luma of 1.1 in a range from 0 to 1 would be dropped to aluma of 1).

Some embodiments stop boosting and attenuating luma values at this pointand move on to operation 1260. However, in some embodiments, compositingthe images 1360A and 1360B also includes a boost of the midtone pixels.Some such embodiments implement the following equation to boost themidtones:Lc[x,y]=Lc[x,y]^(2^((Bm*G[x,y]*(1−G[x,y]))^2)  (14)

In equation (14), the first Lc[x,y] is the luma of the pixel atcoordinates [x,y] in the composite image 1370 after the boost of themidtone pixels. The second Lc[x,y] is the luma of the pixel atcoordinates [x,y] in the composite image before the boost of the midtonepixels. G[x,y] is the value of the pixel at coordinates [x,y] in theGaussian blurred composite 1350. Bm is a scaling factor that determinesthe boost curve. Some embodiments use other equations to boost themidtones. As mentioned above, some embodiments don't boost the midtones.

In some embodiments that generate a composite luminance image 1340(e.g., using equation (7B)) rather than a composite luma image 1340(e.g., using equation (7A)), the shadow-boosted image 1360B, thehighlight-attenuated image 1360A, and the composite image 1370 is aluminance image rather than a luma image. That is, the images 1360A and1360B and 1370 are all luminance images because they are generated(directly or indirectly) from a luminance image 1340 rather than a lumaimage 1340. In some such embodiments, luminance image 1370 is convertedto luma image 1370 by a gamma correction (e.g., raising the luminancevalues of the image 1370 to the power of gamma). The mobile device ofsome embodiments provides the gamma value used to convert luminanceimage 1370 to luma image 1370. The gamma value is 1/2.2 in someembodiments.

The various compositing processes can lead to images with luma valuesclustered in one small area of the available range of values. Forexample, the image may have pixels that are almost all darker than 50%of the available scale or have pixels that are almost all brighter than50% of the available scale. To increase the range of luma values in theimage to take advantage of the available scale, the process 1200 of someembodiments applies (at 1260) a histogram stretching on the luma versionof composite image 1370 to return it to the approximate lumadistribution of the original normally exposed luma image 1320B. Thehistogram stretching generates a histogram of the lumas of the compositeimage 1370 and determines the range of luma between the 0.5th percentileand the 99.5th percentile for image 1370. The process then makes thesame determinations for the pixels of the normally exposed luma image1320B. The process then applies the following equation to the pixels ofthe composite image 1370:Lf[x,y]=(Lc[x,y]−L1)*((H2−L2)/(H1−L1))+L2  (15)

In equation (15), Lf[x,y] is the luma of the pixel at coordinates [x,y]in the final composite image 1380. The Lc[x,y] is the luma of the pixelat coordinates [x,y] in the composite image 1370. L1 is a luma valuethat is dimmer than 99.5% of the pixels in the composite image 1370. H1is a luma value that is brighter than 99.5% of the pixels in thecomposite image 1370. L2 is a luma value that is dimmer than 99.5% ofthe pixels in the normally exposed luma image 1320B. H2 is a luma valuethat is brighter than 99.5% of the pixels in the normally exposed lumaimage 1320B. In some embodiments, the percentiles may be different.

This histogram stretching gives the picture the same overall lightingrange as the normally exposed luma image 1320B. The reason for thepercentile cutoffs is to prevent any pixels with outlying lumas frommaking an image with too compressed or too broad a range compared to theoriginal normally exposed luma image 1320B. Some embodiments then changethe luma values of pixels with luma values above the top of theavailable range to the top value of the range. Some embodiments changethe luma values of pixels with luma values below the bottom of theavailable range to the bottom value of the range.

Some embodiments broaden the luma values to an arbitrary range (e.g.,full available range) in order to take advantage of the full range ofavailable lumas. For example, some embodiments broaden the luma to thefull range when the original normally exposed luma image 1320B has anarrow range of lumas. After the histogram stretching, the process 1200then ends.

The above description of the histogram stretching describes embodimentsthat apply the histogram to a luma composite image 1370. However, insome embodiments, the histogram stretching is applied to the luminancecomposite image 1370 and the gamma correction is applied to a luminanceversion of final composite image 1380 to produce a luma version ofcomposite image 1380.

C. Compositing Chroma Channel Images

Images in a luma, blue-chroma, red-chroma (Y′CbCr) format or luminance,blue-chroma, red-chroma (YCbCr) format have chrominance components (Cb &Cr) that carry color information. Process 1200 composites the luma (orluminance) components of images in those formats, but some embodimentscomposite the chrominance channel images of the images 1310A-1310Cseparately from the compositing of the luma components. In someembodiments, the same masks that are used in compositing the luma imagesare used in compositing the chrominance images. FIG. 14 illustrates theprocess 1400 of some embodiments for compositing chroma channel images.FIG. 14 will be described in relation to FIG. 15. FIG. 15 illustrates anexample of compositing chroma channel images in some embodiments. FIG.15 includes underexposed chroma channel images 1520A, normally exposedchroma channel images 1520B, overexposed chroma channel images 1520C,composite chroma channel image 1530, and imported data 1540 from lumacompositing. Underexposed chroma channel images 1520A include chromavalues (e.g., Cr and Cb) from image 1310A. Normally exposed chromachannel images 1520B include chroma values (e.g., Cr and Cb) from image1310B. Overexposed chroma channel images 1520C include chroma values(e.g., Cr and Cb) from image 1310C. In some embodiments, each set ofchroma channel images (Cb and Cr) has the same operations performed onit. The composite chroma image 1530 of some embodiments also includestwo channels of chroma data. One of ordinary skill in the art willunderstand that in some such embodiments, the compositing process isperformed separately on each chroma channel. However, for clarity, thedescription, below, of the chroma compositing process sometimes refersto “pixels of the composite image”, rather than “pixels of one channelof the composite image”.

The process 1400 begins by receiving (at 1410) overexposure,underexposure and normal exposure masks (e.g., the masks generatedduring the luma compositing process 1200). In FIG. 15, the imported data1540 includes these masks. In some embodiments, such masks are generatedseparately for the process 1400, rather than being copies of the masksin the luma compositing process. Different masks are used for the chromacompositing than the luma compositing in some embodiments. For example,in some embodiments, the masks for the chroma compositing are generatedfrom the final luma composite image. Some embodiments generate one setof masks from the normally exposed luma image and another set of masksfrom the individual luma images and use each set for compositing adifferent type of image component (e.g., one for luma and the other forchroma).

After the masks are received (or generated), the process 1400 generates(at 1420) one chroma channel of a composite image from the masks (e.g.,masks 1330A-1330C) and one channel (i.e., either the Cb or Cr) of thechroma images 1520A-1520C. In some embodiments, the channel of thechroma images 1520A-1520C are composited using the following equation:

$\begin{matrix}{{{Cc}\lbrack {x,y} \rbrack} = {{{Eb}*{{Cb}\lbrack {x,y} \rbrack}*{{Mb}\lbrack {x,y} \rbrack}} + {{En}*{{Cn}\lbrack {x,y} \rbrack}*{{Mn}\lbrack {x,y} \rbrack}} + {{Eu}*{{Cu}\lbrack {x,y} \rbrack}*{{Mu}\lbrack {x,y} \rbrack}}}} & (16)\end{matrix}$

In equation (16), Cc[x,y] is the chroma value of the pixel atcoordinates [x,y] in the composite chroma channel image 1530 (of FIG.15). Cb[x,y] is the chroma value of the pixel at coordinates [x,y] inthe overexposed (bright) chroma channel image 1520C. Cn[x,y] and Cu[x,y]are the chroma values for the normal chroma channel image 1520B andunderexposed chroma channel image 1520A, respectively. Eb is an exposurescaling factor for the exposure of the overexposed chroma channel image1520C. En and Eu are the exposure scaling factors for the normal chromachannel image 1520B and underexposed chroma channel image 1520A,respectively. Mb[x,y] represents the value of the overexposure mask1330C at coordinates [x,y]. Mn[x,y] and Mu[x,y] represent the values forthe normal exposure mask 1330B and underexposure mask 1330A,respectively. The value of a pixel in the mask 1330C determines how mucheffect the corresponding pixel in the overexposed chroma channel image1520C has on the composite chroma. The value of a pixel in the mask1330B determines how much effect the corresponding pixel in the normalchroma channel image 1520B has on the composite chroma. The value of apixel in the mask 1330A determines how much effect the correspondingpixel in the underexposed chroma channel image 1520A has on thecomposite chroma. In each mask 1330A-1330C higher values mean moreeffect. By using the same masks as the luma images, the chromaadjustment ensures that the color data of each pixel in the chromachannel images 1520A-1520C will match the corresponding luma data foreach pixel in the luma images. For example, a particular pixel that gets62% of its luma value from the corresponding pixel in the overexposedluma image 1320C will also get 62% of its chroma values from thecorresponding pixel of the overexposed chroma channel images 1520C.

The process 1400 receives (at 1430) a Gaussian blurred mask. In someembodiments this is a copy of the same Gaussian blurred composite 1350generated from the luma composite image 1340. One of ordinary skill inthe art will understand that the Gaussian blurred composite 1350 canalso be received at an earlier or later point in process 1400. Theprocess 1400 receives (at 1440) a histogram stretching value (e.g.,(H2−L2)/(H1−L1), as seen in equation (15)). This value is calculatedindependently in some embodiments during process 1400 rather than storedduring process 1200 and received during process 1400.

The process 1400 then uses the Gaussian blurred composite 1350 and thehistogram stretching value to adjust (at 1450) the composite chroma.This adjustment also involves multiplying the composite chroma image bya saturation factor in some embodiments. Some embodiments provide apre-programmed saturation factor. A user adjustable saturation factor isprovided in addition to or instead of the pre-programmed saturationfactor in some embodiments. In still other embodiments the chroma imageadjustment is determined by equations (17)-(19):F[x,y]=1+(H2−L2)/(H1−L1)*X*G[x,y]*(1−G[x,y]))  (17)

The saturation factor, F[x,y], in equation (17) is used in someembodiments to adjust the chroma of a pixel at coordinates [x,y] asshown in equation (19), below. L1 is a luma value that is dimmer than99.5% of the pixels in the composite image 1370 (of FIG. 13A or FIG.13B). H1 is a luma value that is brighter than 99.5% of the pixels inthe composite image 1370. L2 is a luma value that is dimmer than 99.5%of the pixels in the normally exposed luma image 1320B. H2 is a lumavalue that is brighter than 99.5% of the pixels in the normally exposedluma image 1320B. X is a saturation factor (e.g., 1.2) that is differentin different embodiments and can be changed (e.g., by the user or themobile device) in some embodiments. In some embodiments, the percentilesused to calculate the histogram stretching factor may be different thanthose shown above. G[x,y] is the value of the pixel at coordinates [x,y]in the Gaussian blurred composite 1350. The factor G*(1−G) is maximizedwhen G=0.5 and minimized when G=1 or G=0. Accordingly, using theGaussian blurred composite 1350 in this way boosts the chroma values ofthose parts of the image that have midtone lumas more than the chromavalues of those parts of the image that have bright or dark pixels.Boosting the colors of the midtone pixels provides a different finalimage than uniformly boosting the color.

In some embodiments, the composite chroma is normalized (at 1460) bydividing the chroma values by a normalization factor generated using thefollowing equation:N[x,y]=(Eb*Mb[x,y])+(En*Mn[x,y])+(Eu*Mu[x,y])  (18)

The normalization factor, N[x,y], in equation (18) is used in someembodiments to adjust the chroma of a pixel at coordinates [x,y] asshown in equation (19). Eb is an exposure scaling factor for theoverexposed chroma channel image 1520C. En and Eu are the exposurescaling factors for the normal chroma channel image 1520B andunderexposed chroma channel image 1520A, respectively. Mb[x,y]represents the value of the overexposure mask 1330C at coordinates[x,y]. Mn[x,y] and Mu[x,y] represent the values of the normal exposuremask 1330B and underexposure mask 1330A, respectively.

Accordingly, in some embodiments, the final composite chroma channelimage 1530 is determined by the following equation:Cf[x,y]=Cc[x,y]*F[x,y]/N[x,y]  (19)

In equation (19), Cf[x,y] is the chroma value of the pixel atcoordinates [x,y] in the composite chroma channel image 1530 (aftersaturation). N[x,y] is a normalization factor (e.g., the normalizationfactor from equation (18)) used to divide the chroma values of thecomposite chroma image. Cc[x,y] is the chroma value of the pixel atcoordinates [x,y] in the composite chroma channel image 1530. F[x,y] isa saturation factor (e.g., the saturation factor from equation (17))used to multiply the chroma of a pixel at coordinates [x,y]. Inembodiments that make these adjustments, the adjustments produce thefinal composite chroma channel image 1530. One of ordinary skill in theart will understand that some embodiments that use equation (19)calculate F[x,y] or N[x,y] using different equations from equations (17)and (18).

The process 1400 then determines (at 1470) whether there is anotherchroma channel image to composite. If there is another chroma channel tocomposite (e.g., if the process 1400 has finished compositing the Cbchroma image, but not the Cr chroma image, then it will adjust the Crchroma image), the process 1400 returns to operation 1420 to apply themasks to the new chroma channel images. In some embodiments, theindividual operations are performed in turn on each chroma channel imagerather than performing operations 1420-1460 on one chroma channel imageand then performing 1420-1460 on the other chroma channel image. Theprocess 1400 is performed on all chroma channels in some embodiments.

While the above chroma related equations describe the compositing ofchroma components of images that have the same resolution as thecorresponding luma (or luminance) components of the images, one ofordinary skill in the art will understand that in some embodiments, thechroma components of the images have a different resolution than theluma (or luminance) components of the images. In some such embodiments,the masks are adjusted to account for the differences in the resolution.For example, some embodiments employ a 4:2:2 format with each pixel inthe chroma component of the image corresponding to two horizontallyadjacent pixels in the luma/luminance component of the image. Becausethe masks of some embodiments have the same resolution as theluma/luminance components of the image, each pixel in a chroma componentof the image corresponds to two horizontally adjacent pixels in thecorresponding mask. In some such embodiments, the value of a chromapixel of an image is weighted by the average value of the correspondingpair of horizontally adjacent pixels in the corresponding mask. In othersuch embodiments, the value of a chroma pixel is weighted by the valueof one or the other of the corresponding pair of horizontally adjacentpixels in the mask (e.g., the value of the leftmost pixel of the pair).Similarly, some embodiments use a 4:2:0 format, in which each chromapixel corresponds to a two-by-two square of pixels in the luma/luminancecomponent (and in the masks). In some such embodiments, the value of achroma pixel is weighted by the average value of the corresponding fourpixels in the mask. In other such embodiments, the value of a chromapixel is weighted by the value of one of the four corresponding pixelsin the mask (e.g., the value of the upper-left pixel of the four).Alternatively, in some embodiments, the compositing of the chromacomponents is performed at the resolution of the mask, generating acomposite chroma component with the same resolution as the compositeluma/luminance component. In some such embodiments, the composite chromacomponent is converted back to the resolution of the original chromacomponent at some point.

The compositing module of some embodiments joins the final luma image1380 (of FIG. 13A or FIG. 13B) and each channel of the final compositechroma channel image 1530 (of FIG. 15) to produce a final HDR image.Alternatively, the compositing module in some embodiments converts thefinal luma image 1380 and the final composite chroma channel image 1530to an RGB format (e.g., sRGB) to produce a final HDR image.

D. Adjusting for Exposure Conditions

The mobile devices of some embodiments automatically adjust the exposuretime of the normally exposed images to account for the local lightingconditions at the time that the mobile device is taking images. In someembodiments, the exposure time is the time between refreshes of the CMOSsensor of the camera. The mobile device compensates for lower lightingconditions by increasing the exposure time of the normal durationexposure. In some such embodiments, the mobile device also has an upperlimit on the duration of an exposure. The exposure duration for theoverexposed image in some embodiments is a multiple of the normalexposure duration (e.g., four times the normal exposure duration). Inlow light conditions, the increased duration of the normal exposure andthe default multiplier for the exposure time of the overexposed imagemay result in an exposure time for the overexposed image that is longerthan the upper limit allowed by the mobile device. To adjust for theseconditions, some embodiments use an exposure multiplier for theoverexposed image that is lower than the default value (e.g., amultiplier of 2 rather than the default multiplier of 4). Thecompositing processes of some embodiments increase the scaling factor Ebaccordingly.

In some cases, the light is so dim that the normal exposure duration isat or near the upper limit of allowed exposure times. In such cases, theoverexposure duration is forced to be no longer than the same length (oralmost the same length) as the normal exposure duration. The mobiledevice of some embodiments takes the overexposed image for the sameamount of time (or for almost the same amount of time) as the normallyexposed image and performs the compositing anyway. One of ordinary skillin the art will understand that in cases where the normally exposedimage and the overexposed image are taken with the same exposureduration the images could be referred to as two normally exposed imagesrather than as a normally exposed image and an overexposed image.

In cases where the normal exposure duration is the maximum allowedexposure of the mobile device, some embodiments composite two normallyexposed images taken with the same exposure duration in order to reducenoise levels in the final image. In cases where the normal exposureduration is near the maximum allowed exposure of the mobile device, theoverexposed image is taken with an exposure duration which is onlyslightly longer than the exposure duration of the normally exposedimage. Because of the low ratio of exposure durations, the overexposedimage in such a case does not increase the dynamic range as much as itordinarily would. However, some embodiments composite the overexposedimage and the normally exposed image for the small increase in dynamicrange and/or to reduce noise levels in the final image.

In embodiments that limit the exposure duration, the scaling factor Ebis increased in accord with the changed ratio of exposure times when theoverexposure duration is capped. In some of the same or otherembodiments, the mobile device uses a flash while taking the overexposedimage and does not use the flash while taking the normally exposed imagein order to compensate for the lack of a longer exposure time for theoverexposed image. In some embodiments, the flash is used when thenormal exposure duration is within some particular threshold of themaximum exposure duration. For example, in some embodiments, the flashis used when the normal exposure duration is more than 50% of themaximum exposure duration. In other embodiments, other percentages areused as the threshold. In some embodiments, when the normal exposureduration is above the threshold, the overexposure duration is set to themaximum exposure duration (e.g., a lower multiple of the normal exposureduration than would be used in brighter lighting conditions) and theflash is used for the overexposed duration, but not the normal durationor the underexposed duration. In some embodiments, in cases where theflash is used, the mobile device captures and composites the overexposedand normally exposed images, but does not capture an underexposed imageand/or does not composite an underexposed image with the other twoimages.

The mobile devices of some embodiments have a lower limit on the lengthof an exposure. In such embodiments, in bright light conditions, thedefault multiplier for the exposure time of the underexposed image mayresult in an exposure time shorter than the lower limit that the mobiledevice allows. In some such embodiments, the underexposed image uses anexposure multiplier higher than it otherwise would (e.g., an exposuremultiplier of ½ rather than a default exposure multiplier of ¼). In somecases, the light is so bright that the normal exposure time is at thelower limit of allowed exposure times. In such cases, the underexposureis taken for the same amount of time as the normally exposed image(resulting in two normally exposed images) and used in the compositingin order to reduce noise levels in the final image. In some suchembodiments, the scaling factor Eu is decreased in accord with thechanged ratio of exposure times.

While the description of many of the embodiments described hereinreferred to taking and compositing three images (e.g., an underexposedimage, a normally exposed image, and an overexposed image), one ofordinary skill in the art will understand that in other embodimentsother numbers of images can be taken and/or composited. For example,some embodiments composite two images (e.g., an underexposed image and anormally exposed image) instead of three images.

Furthermore, some embodiments take different numbers of images dependingon the lighting conditions. For example, some such embodiments compositethree images when the mobile device is capturing images of a scene withboth dark areas and light areas and composite two images when the mobiledevice is capturing images with little or no dark areas or little or nobright areas. When a scene has little or no dark areas, some suchembodiments composite a normally exposed image and an underexposedimage. When a scene has little or no bright areas, some such embodimentscomposite a normally exposed image and an underexposed image. Some suchembodiments use a histogram of one or more images (e.g., a previewimage) to determine whether a scene has little or no bright areas orlittle or no dark areas. Some embodiments that composite two images wheneither bright or dark areas are small or absent still use three imageswhen both bright and dark areas are small or absent (i.e., a scene thatis predominantly midtones). Alternatively, rather than excluding typesof images based on qualities of the individual areas of a scene to becaptured, some embodiments exclude the overexposed image when capturingscenes that are above a certain total light level and some embodimentsexclude the underexposed image when capturing scenes that are below acertain total light level.

While the above descriptions included the term “image” or “images” formany sets of data (e.g., Gaussian blurred image, shadow-boosted image,overexposed image, etc.), one of ordinary skill in the art willunderstand that in some embodiments, the data in these “images” is notdisplayed in a visual form in the normal course of practicing theembodiment. In such embodiments, the data in the “images” is used tomanipulate and adjust other data that ultimately is displayed in visualform. Some embodiments display only the final product, the HDR image.However, other embodiments display one or more of the other images aswell as the final HDR image.

The embodiments that combine one flash illuminated image with one ormore non-flash illuminated images allow the device's HDR image capturemode to operate in conjunction with the device's flash mode. Otherembodiments, however, only allow the device to operate in either theflash mode or the HDR mode. Accordingly, when the automatic flash modeis enabled, these embodiments disable the HDR image capture mode.

E. Image Formats

Many of the embodiments described above are described in terms of one ormore image formats. One of ordinary skill in the art will understandthat different embodiments provide and manipulate images in differentformats. In some embodiments, color images are provided as threechannels of information, such as a luma channel and two chroma channels.One color format used for this type of information is the Y′CbCr (luma,blue-chroma, and red-chroma) color format. The camera function of themobile device of some embodiments automatically provides the images in aY′CbCr format. Light sensors (e.g., a charge coupled device) of themobile device measure the intensity of light that reaches each sensorand generate a luminance value (Y) proportional to the intensity. Themobile device generates the Y′ component of the image by takingluminance data received from light sensors of the camera and applying agamma correction to the luminance data (e.g. mathematically raising theluminance value to some power such as 1/2.2).

In the Y′CbCr format, the luma (Y′) channel carries the brightnessinformation of the image; the Cb (sometimes written in outsidereferences as C_(B)) channel carries the information on how much theblue values of the image differ from the luma (Y′) value; and the Cr(sometimes written in outside references as C_(R)) channel carries theinformation on how much the red values of the image differ from the luma(Y′) value. Effectively, the luma channel (Y′) provides a black & white(and grey) image and the chroma channels (Cb and Cr) add color to theimage. In some embodiments, the scale of the Y′CbCr values can bechanged arbitrarily. For the calculations described herein, the luma(Y′) is scaled to a maximum of 1 and a minimum of 0 for the calculationsand the chroma (Cb & Cr) are scaled from −0.5 to 0.5. However, otherscales are possible within the scope of some embodiments. For example,luma (Y′) is scaled from 0 to 255 in some embodiments. Other embodimentsscale luma from 16 to 235 and scale chroma from 16 to 240. Other colorformats, such as YUV, etc. are used in some embodiments.

Some mobile devices capture images in the YCbCr color format directlyand then convert the images to RGB images (e.g., standard RGB) or toY′CbCr images. In some embodiments, the operations described above areperformed on the images as captured in Y′CbCr format (with any necessaryrescaling from the scale of the mobile device). In other embodiments,the operations are performed on images initially received in an RGBformat and converted to Y′CbCr. The operations and mathematicalequations below assume a Y′CbCr color format, however other embodimentsuse other color formats (e.g., YUV, etc.). In some embodiments withother color formats, the operations and equations are adjustedaccordingly. Similarly, some embodiments use luminance values ratherthan luma values when generating the decimated images and the bitmapsused to align the images as described above.

While the processes and equations described above are described in termsof specific image formats, one of ordinary skill in the art willunderstand that the processes and equations can be used on other imageformats in some embodiments. For example, in some places, the abovedescription refers to luma data and in some places it refers toluminance data. However, unless otherwise specified, the equations andprocesses described herein as applying to luma values in someembodiments are applied to luminance values in other embodiments andvice-versa. One of ordinary skill in the art will understand that lumaand luminance are only two examples of formats for image intensity dataand that the described processes and equations described herein inrelation to luminance and luma can be applied in some embodiments toother formats that store intensity information. For example, someembodiments perform the above described operations on the red, blue, andgreen components of images in an RGB format, an sRGB format, an R′G′B′format (i.e., a gamma corrected RGB format), or other formats that donot provide intensity data and color data as separate components. Someembodiments that perform such operations on red, blue, and greencomponents convert between gamma corrected and non-gamma correctedformats using the same operations described above or similar operations.

Similarly, the equations and processes described herein as applying tochroma data can be applied in some embodiments to other formats thatstore color data separately from intensity data. Furthermore, althoughthe description above points out some specific parts of processes atwhich conversion from one format to another (e.g., luma to luminance orRGB to luma) can take place, one of ordinary skill in the art willunderstand that conversion from one image format to another can takeplace at any stage or stages of the processes in some embodiments.

VI. Mobile Device

FIG. 16 is an example of a mobile computing device 1600 of someembodiments. The implementation of a mobile computing device includesone or more processing units 1605, memory interface 1610 and aperipherals interface 1615. Each of these components that make up thecomputing device architecture can be separate components or integratedin one or more integrated circuits. These various components can also becoupled together by one or more communication buses or signal lines.

The peripherals interface 1615 couple to various sensors and subsystems,including a camera subsystem 1620, a wireless communication subsystem(s)1625, audio subsystem 1630, I/O subsystem 1635, etc. The peripheralsinterface 1615 enables communication between processors and peripherals.Peripherals such as an orientation sensor 1645 or an acceleration sensor1650 can be coupled to the peripherals interface 1615 to facilitate theorientation and acceleration functions.

The camera subsystem 1620 can be coupled to one or more optical sensors1640 (e.g., a charged coupled device (CCD) optical sensor, acomplementary metal-oxide-semiconductor (capture modules) opticalsensor) for one or more cameras of the device. In some embodiments, thedevice has just one camera, while in other embodiments the device hasmore than one (e.g., two) cameras. In some embodiments, the device hascameras on multiple sides of the device (e.g., a camera on the frontside of the device and a camera on the back side of the device). Thecamera subsystem 1620 coupled with the sensors may facilitate camerafunctions, such as image and/or video data capturing. Wirelesscommunication subsystems 1625 may serve to facilitate communicationfunctions. Wireless communication subsystems 1625 may include radiofrequency receivers and transmitters, and optical receivers andtransmitters. They may be implemented to operate over one or morecommunication networks such as a GSM network, a Wi-Fi network, Bluetoothnetwork, etc. The audio subsystems 1630 is coupled to a speaker 1631 anda microphone 1632 to facilitate voice-enabled functions, such as voicerecognition, digital recording, etc.

I/O subsystem 1635 involves the transfer between input/output peripheraldevices, such as a display, a touch screen, etc., and the data bus ofthe CPU through the peripherals interface 1615. I/O subsystem 1635 caninclude a touch-screen controller 1655 and other input controllers 1660to facilitate these functions. Touch-screen controller 1655 can becoupled to the touch screen 1665 and detect contact and movement on thescreen using any of multiple touch sensitivity technologies. Other inputcontrollers 1660 can be coupled to other input/control devices, such asone or more buttons.

Memory interface 1610 can be coupled to memory 1670, which can includehigh-speed random access memory and/or non-volatile memory such as flashmemory. Memory can store an operating system (OS) 1672. The OS 1672 caninclude instructions for handling basic system services and forperforming hardware dependent tasks.

Memory can also include communication instructions 1674 to facilitatecommunicating with one or more additional devices; graphical userinterface instructions 1676 to facilitate graphical user interfaceprocessing; image processing instructions 1678 to facilitate imagerelated processing and functions; phone instructions 1680 to facilitatephone-related processes and functions; media exchange and processinginstructions 1682 to facilitate media communication andprocessing-related processes and functions; camera instructions 1684 tofacilitate camera-related processes and functions; and HDR imagegeneration instructions 1686 to facilitate in the HDR generationprocesses and functions. The above identified instructions need not beimplemented as separate software programs or modules. Various functionsof mobile computing device can be implemented in hardware and/or insoftware, including in one or more signal processing and/or applicationspecific integrated circuits.

FIG. 17 illustrates a touch I/O device. The above-described embodimentsmay include the touch I/O device 1701 that can receive touch input forinteracting with computing system 1703, as shown in FIG. 17, via wiredor wireless communication channel 1702. Touch I/O device 1701 may beused to provide user input to computing system 1703 in lieu of or incombination with other input devices such as a keyboard, mouse, etc. Oneor more touch I/O devices 1701 may be used for providing user input tocomputing system 1703. Touch I/O device 1701 may be an integral part ofcomputing system 1703 (e.g., touch screen on a laptop) or may beseparate from computing system 1703.

Touch I/O device 1701 may include a touch sensitive panel which iswholly or partially transparent, semitransparent, non-transparent,opaque or any combination thereof. Touch I/O device 1701 may be embodiedas a touch screen, touch pad, a touch screen functioning as a touch pad(e.g., a touch screen replacing the touchpad of a laptop), a touchscreen or touchpad combined or incorporated with any other input device(e.g., a touch screen or touchpad disposed on a keyboard) or anymulti-dimensional object having a touch sensitive surface for receivingtouch input.

In one example, touch I/O device 1701 embodied as a touch screen mayinclude a transparent and/or semitransparent touch sensitive panelpartially or wholly positioned over at least a portion of a display.According to this embodiment, touch I/O device 1701 functions to displaygraphical data transmitted from computing system 1703 (and/or anothersource) and also functions to receive user input. In other embodiments,touch I/O device 1701 may be embodied as an integrated touch screenwhere touch sensitive components/devices are integral with displaycomponents/devices. In still other embodiments a touch screen may beused as a supplemental or additional display screen for displayingsupplemental or the same graphical data as a primary display andreceiving touch input.

Touch I/O device 1701 may be configured to detect the location of one ormore touches or near touches on device 1701 based on capacitive,resistive, optical, acoustic, inductive, mechanical, chemicalmeasurements, or any phenomena that can be measured with respect to theoccurrences of the one or more touches or near touches in proximity todevice 1701. Software, hardware, firmware or any combination thereof maybe used to process the measurements of the detected touches to identifyand track one or more gestures. A gesture may correspond to stationaryor non-stationary, single or multiple, touches or near touches on touchI/O device 1701. A gesture may be performed by moving one or morefingers or other objects in a particular manner on touch I/O device 1701such as tapping, pressing, rocking, scrubbing, twisting, changingorientation, pressing with varying pressure and the like at essentiallythe same time, contiguously, or consecutively. A gesture may becharacterized by, but is not limited to a pinching, sliding, swiping,rotating, flexing, dragging, or tapping motion between or with any otherfinger or fingers. A single gesture may be performed with one or morehands, by one or more users, or any combination thereof.

Computing system 1703 may drive a display with graphical data to displaya graphical user interface (GUI). The GUI may be configured to receivetouch input via touch I/O device 1701. Embodied as a touch screen, touchI/O device 1701 may display the GUI. Alternatively, the GUI may bedisplayed on a display separate from touch I/O device 1701. The GUI mayinclude graphical elements displayed at particular locations within theinterface. Graphical elements may include but are not limited to avariety of displayed virtual input devices including virtual scrollwheels, a virtual keyboard, virtual knobs, virtual buttons, any virtualUI, and the like. A user may perform gestures at one or more particularlocations on touch I/O device 1701 which may be associated with thegraphical elements of the GUI. In other embodiments, the user mayperform gestures at one or more locations that are independent of thelocations of graphical elements of the GUI. Gestures performed on touchI/O device 1701 may directly or indirectly manipulate, control, modify,move, actuate, initiate or generally affect graphical elements such ascursors, icons, media files, lists, text, all or portions of images, orthe like within the GUI. For instance, in the case of a touch screen, auser may directly interact with a graphical element by performing agesture over the graphical element on the touch screen. Alternatively, atouch pad generally provides indirect interaction. Gestures may alsoaffect non-displayed GUI elements (e.g., causing user interfaces toappear) or may affect other actions within computing system 1703 (e.g.,affect a state or mode of a GUI, application, or operating system).Gestures may or may not be performed on touch I/O device 1701 inconjunction with a displayed cursor. For instance, in the case in whichgestures are performed on a touchpad, a cursor (or pointer) may bedisplayed on a display screen or touch screen and the cursor may becontrolled via touch input on the touchpad to interact with graphicalobjects on the display screen. In other embodiments in which gesturesare performed directly on a touch screen, a user may interact directlywith objects on the touch screen, with or without a cursor or pointerbeing displayed on the touch screen.

Feedback may be provided to the user via communication channel 1702 inresponse to or based on the touch or near touches on touch I/O device1701. Feedback may be transmitted optically, mechanically, electrically,olfactory, acoustically, or the like or any combination thereof and in avariable or non-variable manner.

These functions described above can be implemented in digital electroniccircuitry, in computer software, firmware or hardware. The techniquescan be implemented using one or more computer program products.Programmable processors and computers can be included in or packaged asmobile devices. The processes and logic flows may be performed by one ormore programmable processors and by one or more programmable logiccircuitry. General and special purpose computing devices and storagedevices can be interconnected through communication networks.

Some embodiments include electronic components, such as microprocessors,storage and memory that store computer program instructions in amachine-readable or computer-readable medium (alternatively referred toas computer-readable storage media, machine-readable media, ormachine-readable storage media). Some examples of such computer-readablemedia include RAM, ROM, read-only compact discs (CD-ROM), recordablecompact discs (CD-R), rewritable compact discs (CD-RW), read-onlydigital versatile discs (e.g., DVD-ROM, dual-layer DVD-ROM), a varietyof recordable/rewritable DVDs (e.g., DVD-RAM, DVD-RW, DVD+RW, etc.),flash memory (e.g., SD cards, mini-SD cards, micro-SD cards, etc.),magnetic and/or solid state hard drives, read-only and recordableBlu-Ray® discs, ultra density optical discs, any other optical ormagnetic media, and floppy disks. The computer-readable media may storea computer program that is executable by at least one processing unitand includes sets of instructions for performing various operations.Examples of computer programs or computer code include machine code,such as is produced by a compiler, and files including higher-level codethat are executed by a computer, an electronic component, or amicroprocessor using an interpreter.

While the above discussion primarily refers to microprocessor ormulti-core processors that execute software, some embodiments areperformed by one or more integrated circuits, such as applicationspecific integrated circuits (ASICs) or field programmable gate arrays(FPGAs). In some embodiments, such integrated circuits executeinstructions that are stored on the circuit itself.

As used in this specification and any claims of this application, theterms “computer”, “server”, “processor”, and “memory” all refer toelectronic or other technological devices. These terms exclude people orgroups of people. For the purposes of the specification, the termsdisplay or displaying means displaying on an electronic device. As usedin this specification and any claims of this application, the terms“computer readable medium,” “computer readable media,” “machine readablemedium,” or “machine readable media” are entirely restricted totangible, physical objects that store information in a form that isreadable by a computer, computing device, or other electronic devicewith one or more processing units. These terms exclude any wirelesssignals, wired download signals, and any other ephemeral signals.

While the invention has been described with reference to numerousspecific details, one of ordinary skill in the art will recognize thatthe invention can be embodied in other specific forms without departingfrom the spirit of the invention. For instance, while severalembodiments are described above for mobile devices, one of ordinaryskill in the art will realize that the device in other embodiments mightbe a non-mobile device such as a desktop computer.

In addition, a number of the figures (including FIGS. 4, 6, 7, 9, 10,12, and 14) conceptually illustrate processes. The specific operationsof these processes may not be performed in the exact order shown anddescribed. The specific operations may not be performed in onecontinuous series of operations, and different operations may beperformed in different embodiments. Furthermore, the process could beimplemented using several sub-processes, or as part of a larger macroprocess. Also, operations that appear sequentially may be performed inan interlaced manner. Thus, one of ordinary skill in the art wouldunderstand that the invention is not to be limited by the foregoingillustrative details, but rather is to be defined by the appendedclaims.

What is claimed is:
 1. A method of aligning a pair of original images,the method comprising: defining a plurality of different pairs of imagesat a plurality of different resolutions, wherein the plurality ofdifferent pairs of images is associated with a plurality of differentpairs of bitmaps, and each particular bitmap is a bitmap of a particularoriginal image at a particular resolution; and hierarchically aligningthe pair of original images by first aligning the pair of images at thelowest resolution and then aligning each pair of images at each higherresolution based on the alignments of the pair of images at the lowerresolutions, the hierarchical aligning comprising, for each particularresolution in a subset of resolutions: for at least one particular imageat the particular resolution, dividing the particular image into aplurality of tiles for use in identifying corresponding portions in theother image in the pair at the particular resolution; and comparing thepair of images by using tiles that are suitable for the comparison whilediscarding tiles that are unsuitable from the comparison; whereinidentifying suitable and unsuitable tiles in a particular image at aparticular resolution comprises identifying tiles that have more than athreshold level of black pixels or tiles that have more than a thresholdlevel of white pixels as unsuitable.
 2. The method of claim 1, whereincomparing the pair of images at at least one resolution comprisesfinding an offset that aligns the pair of images at the particularresolution using the portions suitable for performing the alignment andan offset that aligns the images at a lower resolution.
 3. The method ofclaim 2, wherein the finding the offset at the particular resolutioncomprises: resizing the found offset that aligns the images at the lowerresolution to account for the difference in the resolution between thelower resolution and the particular resolution; and using the resizedoffset as a starting offset for finding the offset that aligns theimages at the particular resolution.
 4. The method of claim 2, whereinfinding an offset comprises determining which particular offset of alimited number of candidate offsets provides the closest alignment ofthe images.
 5. The method of claim 4, wherein the limited number ofcandidate offsets comprises all offsets within one pixel horizontallyand one pixel vertically of a starting offset.
 6. The method of claim 4,wherein the limited number of candidate offsets does not comprise anyoffsets more than one pixel horizontally or more than one pixelvertically from the starting offset.
 7. The method of claim 1, whereindefining a plurality of different pairs of images at a plurality ofdifferent resolutions comprises generating a plurality of versions ofeach original image at a plurality of resolutions, wherein generatingeach version of each image at a particular resolution comprisesdecimating a higher resolution version of the image.
 8. The method ofclaim 7, wherein the decimating a higher resolution version comprisesgenerating the version at a particular resolution by sub-sampling thehigher resolution version.
 9. The method of claim 1, wherein the subsetof resolutions do not include a plurality of lower resolutions butcomprise a plurality of higher resolutions.
 10. A non-transitory machinereadable medium of a mobile device, the machine readable medium storinga program that when executed by at least one processing unit aligns andcomposites a plurality of images, the program comprising sets ofinstructions for: at each particular resolution of a plurality ofresolutions: generating a bitmap at the particular resolution for eachimage in the pair of images; tiling one of the pair of bitmaps if whenthe particular resolution is one of a subset of the resolutions;discarding any tile that is not suitable for comparison with portions ofthe other bitmap, wherein identifying tiles that are not suitable at theparticular resolution comprises identifying tiles that have more than athreshold level of black pixels or tiles that have more than a thresholdlevel of white pixels as unsuitable; and finding an offset that alignsthe pair of images at that the particular resolution (i) by using anynon-discarded tiles, and (ii) when the particular resolution is not thelowest resolution, by using an offset that aligns the images at a lowerresolution.
 11. The machine readable medium of claim 10, wherein theprogram further comprises sets of instructions for: rescaling a foundoffset that aligns the images at the lower resolution; and using therescaled offset as a starting offset for finding an offset of theparticular resolution.
 12. The machine readable medium of claim 11,wherein the set of instructions for finding an offset comprises a set ofinstructions for determining which particular offset of a limited numberof candidate offsets provides the closest alignment of the images. 13.The machine readable medium of claim 10, wherein the program furthercomprises a set of instructions for generating a plurality of versionsof each image of the pair of images at a plurality of resolutions,wherein the set of instructions for generating a version at a particularresolution comprises a set of instructions for decimating a higherresolution version of the image.
 14. The machine readable medium ofclaim 13, wherein the set of instructions for decimating a higherresolution version comprises a set of instructions for generating theversion at a particular resolution as a copy of the higher resolutionversion, wherein the copy has half the number of pixels vertically andhalf the number of pixels horizontally as the higher resolution versionof the pair of images.
 15. The machine readable medium of claim 14,wherein the copy is generated by sub-sampling the higher resolutionversion.
 16. The computer readable medium of claim 10, wherein the setof instructions for generating a bitmap comprises a set of instructionsfor creating a 1-bit bitmap with pixels that correspond to the pixels ofthe image, wherein a first value of pixels in the bitmap correspond topixels in the image comprising all pixels in the image that are abovethe median brightness of pixels in the image and a second value ofpixels in the bitmap correspond to pixels in the image comprising allpixels in the image that are below the median brightness.
 17. The methodof claim 10, wherein the subset of resolutions do not include aplurality of lower resolutions but comprise a plurality of higherresolutions.
 18. A mobile device, comprising: a) a camera for capturinga plurality of images; b) at least one processing unit; c) a machinereadable medium storing an alignment module that when executed by the atleast one processing unit aligns the plurality of images, the alignmentmodule comprising sets of instructions for: defining a plurality ofdifferent pairs of images at a plurality of different resolutions,wherein the plurality of different pairs of images is associated with aplurality of different pairs of bitmaps, and each particular bitmap is abitmap of a particular original image at a particular resolution; andhierarchically aligning the pair of original images by first aligningthe pair of images at the lowest resolution and then aligning each pairof images at each higher resolution based on the alignments at the pairof images at the lower resolutions, the hierarchically aligningcomprising, for each particular resolution in a subset of resolutions:for at least one particular image at the particular resolution, dividingthe particular image into a plurality of tiles for use in identifyingcorresponding portions in the other image in the pair at the particularresolution; and comparing the pair of images by using tiles that aresuitable for the comparison while discarding tiles that are unsuitablefrom the comparison; wherein identifying suitable and unsuitable tilesin a particular image at a particular resolution comprises identifyingtiles that have more than a threshold level of black pixels or tilesthat have more than a threshold level of white pixels as unsuitable; andcompositing the aligned pair of original images to produce a highdynamic range image.
 19. The mobile device of claim 18, wherein the setof instructions for comparing the pair of images at at least oneresolution comprises a set of instructions for finding an offset thataligns the pair of images at the particular resolution using theportions suitable for performing the alignment and an offset that alignsthe images at a lower resolution.
 20. The mobile device of claim 19,wherein the set of instructions for finding the offset at the particularresolution comprises sets of instructions for: resizing the found offsetthat aligns the images at the lower resolution to account for thedifference in the resolution between the lower resolution and particularresolution; and using the resized offset as a starting offset forfinding the offset that aligns the images at the particular resolution.21. The mobile device of claim 19, wherein the set of instructions forfinding an offset comprises a set of instructions for determining whichparticular offset of a limited number of candidate offsets provides theclosest alignment of the images.
 22. The mobile device of claim 21,wherein the limited number of candidate offsets comprises all offsetswithin one pixel horizontally and one pixel vertically from the initialoffset.
 23. The mobile device of claim 21, wherein the limited number ofcandidate offsets does not comprise any offsets more than one pixelhorizontally or more than one pixel vertically from the initial offset.24. The mobile device of claim 18, wherein the set of instructions fordefining a plurality of different pairs of images at a plurality ofdifferent resolutions comprises a set of instructions for generating aplurality of versions of each original image at a plurality ofresolutions, wherein the set of instructions for generating each versionof each image at a particular resolution comprises a set of instructionsfor decimating a higher resolution version of the image.
 25. The mobiledevice of claim 24, wherein the set of instructions for decimating ahigher resolution version comprises a set of instructions for generatingthe version at a particular resolution by sub-sampling the higherresolution version.
 26. The mobile device of claim 18, wherein theexclusion discarding of the unsuitable portions from the comparisondecreases a number of operations performed by the processor to executethe sets of instructions of the alignment module in order to align theplurality of images.
 27. The method of claim 18, wherein the subset ofresolutions do not include a plurality of lower resolutions but comprisea plurality of higher resolutions.